星空网 > 软件开发 > Java

java web 相对路径中已/开头和不已/开头的区别

通俗的讲,有/会从跟目录开始算,没有会从当前目录开始算

1.前台页面

​页面中向服务器页面请求静态资源且没有指定<base href="<%=basePath%>">

访问以下页面​

localhost:8080/resolvent/​index.jsp

localhost:8080/resolvent/​servlet/dnf

有/的​

跟目录是域名+端口号(localhost:8080)

请求以下资源​

<script type="text/css" src='/images/loading.gif' data-original=''/demo.js"></script>

最终浏览器发送的请求都是​localhost:8080/demo.js

没有/

<script type="text/css" src='/images/loading.gif' data-original=''demo.js"></script>​

​localhost:8080/resolvent/demo.js  当前目录localhost:8080/resolvent/

localhost:8080/resolvent/servlet/demo.js​ 当前目录 localhost:8080/resolvent/servlet/

2.后台代码

请求转发,请求重定向,已以下两个url为例

​​localhost:8080/resolvent/servlet/dnf

localhost:8080/resolvent/index.jsp

​有/的

根目录是​(localhost:8080/resolvent)

request.getRequestDispatcher("/login.jsp").forward(request,response);​

最后都会定位到​

​localhost:8080/resolvent/login.jsp

没有/

request.getRequestDispatcher("login.jsp").forward(request,response);​

localhost:8080/resolvent/servlet/login.jsp​  当前目录localhost:8080/resolvent/servlet/

localhost:8080/resolvent/login.jsp​  当前目录localhost:8080/resolvent/




原标题:java web 相对路径中已/开头和不已/开头的区别

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流