免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
request.getContextPath()

今天終于明白了jsp中的request.getContextPath()是怎么回事了。

request.getContextPath()  返回站點(diǎn)的根目錄

request.getRealpath("/")得到的是實(shí)際的物理路徑,也就是你的項(xiàng)目所在服務(wù)器中的路徑

request.getScheme() 等到的是協(xié)議名稱,默認(rèn)是http

request.getServerName() 得到的是在服務(wù)器的配置文件中配置的服務(wù)器名稱 比如:localhost .baidu.com 等等

request.getServerPort() 得到的是服務(wù)器的配置文件中配置的端口號(hào) 比如 8080等等

有一個(gè)例子來(lái)說(shuō)明吧

有個(gè)web應(yīng)用程序 名稱就是demo

 <%
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort();
    String path = request.getScheme() + "://" + request.getServerName()
            + ":" + request.getServerPort() + request.getContextPath()
            + "/";
    String filePath=path+"resources/";
    session.setAttribute("path", path);
    session.setAttribute("basePath", basePath);
    session.setAttribute("filePath", filePath);
%>

以上這段代碼是 demo中每一個(gè)jsp頁(yè)面中都包含的一段代碼

其中 request.getContextPath() = /demo

basePath = http://localhost:8080

path = http://localhost:8080/demo/

filePath = http://localhost:8080/demo/resources/

用法:

如果在jsp界面中引用resources/images/文件夾下面的圖片icon.png寫(xiě)法如下:

<img src="${filePath }images/icon.png" />或者

 <img src="${path}resources/images/icon.png" />

同理 如果在resources/css/文件夾下引用style.css寫(xiě)法如下:

<link href="${filePath} css/style.css" rel="stylesheet" type="text/css" />

<link href="${path} resources/css/style.css" rel="stylesheet" type="text/css" />

OK!

 

 

 

 

 

 

參考文章:http://www.cnblogs.com/yqskj/articles/2226401.html

 

 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Struts2學(xué)習(xí)筆記----Path路徑問(wèn)題
JSP的相對(duì)路徑深入研究(多次完善)
jsp中 <jsp:include> 中使用絕對(duì)路徑的問(wèn)題 ,不能用${ctx}
request.getScheme()+“://”+request.getServerName()+":"+request.getServerPort()+request.getContextPath
一個(gè)完整的簡(jiǎn)單jsp+servlet實(shí)例,實(shí)現(xiàn)簡(jiǎn)單的登錄
getRequestURI,getRequestURL的區(qū)別
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服