『壹』 javaweb項目在配置文件中定義的localhost地址為什麼會隨伺服器的不同而改變
myproperties.getlocalhost這個取得是配置文件里的值吧,你全局搜索下配置文件,以 .properties結尾的,這些都是配置好的
『貳』 java web項目 相對路徑怎麼寫
servlet裡面通過String basePath=session.getServletContext().getRealPath("/");獲取webRoot目錄真實路徑。
比如d:\tomcat 6\webapps\項目名
webRoot下面的resources目錄通過File path = new File(basePath, "resources");獲取
其它同理
如果是jsp的話,獲專取resources目錄直屬接通過「<%=request.getContextPath()%>/resources」獲取
『叄』 本地運行javaweb項目,通過資料庫獲取url後,頁面地址不出現localhost:8080,直接顯示資料庫獲取的url.
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>中引抄入襲了<base href="<%=basePath%>">沒有?
『肆』 java web項目,修改瀏覽器訪問地址
<Hostname="localhost"appBase="webapps"
unpackWARs="true"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
<!--加入如下配置-->
<Contextpath=""docBase="/Project1"reloadable="true"/>
</Host>
在你的 tomcat / conf 目錄下 修改專 server.xml
在最後的 <host></host> 標簽屬中,添加如下配置
<Context path="" docBase="/Project1" reloadable="true"/>
『伍』 Java web項目訪問路徑問題。求解啊!
images的url寫成復src="${pageContext.request.contextPath}/images/logo.jpg"
一般會制把${pageContext.request.contextPath}這部分提取出來,在jsp寫成:
<% String path = request.getContextPath();%>
如圖:
則images路徑可以寫成src="<%=path%>/images/logo.jpg"
訪問login.jsp頁面的話,寫成http://ip:埠號/CityInfo/pages/login.jsp
『陸』 java web項目小問題 我想直接通過url地址訪問途中的 main.jsp文件 請問地址是怎麼寫
ip:埠/項目名/main.jsp
注意:不能通過url直接訪問WEB-INF文件夾下的文件。