web应用 相对路径 绝对路径 总结

参考资料: 
http://www.iteye.com/topic/553749 
http://www.iteye.com/topic/718443 

上面两篇文章写的很好,我做下补充和总结。 

路径分绝对和相对两种 
  ./ 表示当前路径,../表示上一路径 
  直接写文件名. 或 ./  或 ../ 都是相对路径 除了这些写法都是绝对路径  a.jsp路径和代码如下 
+webRoot 
  -s1 
     a.jsp 

Java代码   收藏代码
  1. //我的服务器地址加上应用地址是 “http://localhost:8080/imageShow/”,文件夹路径为  
  2. //     
  3.   
  4. // 实际路径 http://localhost:8080/imageShow/s1/s1/b.html  
  5. <a href="s1/b.html">b.html</a>  
  6.   
  7. // 实际路径 http://localhost:8080/imageShow/b.html  
  8. <a href="../b.html">b.html</a>  
  9.   
  10. //实际路径 http://localhost:8080/imageShow/s1/b.html  
  11. <a href="./b.html">b.html</a>  
  12.   
  13. // 实际路径 http://localhost:8080/imageShow/s1/b.html  与上一个样  
  14. <a href="b.html">b.html</a>  

常见绝对路径 
1. http://localhost:8080/imageShow/includetest/s1/a.jsp 
2.F:\冰河\学习资料\开源 代码 struts2 pager 
3.以“ /”开头。 
1和2没什么好解释的 
“/”在jsp中表示 "http://机器IP:端口号/应用名/" 
注意jsp路径是指 jsp中除html标签以外的标签如 <%@include file"/b.html"%>或 <jsp:include page="/b.html"/> 

Java代码   收藏代码
  1. <%@include file"/s1/a.html"%>//这样才能找到a.html 这个是绝对路径写法  
  2. jsp:include指令同理  

“/”在Servlet中路径表示 

转发请求时:"/"表示“http://服务器IP:8080/Web应用名/”,例如:String forward = "/s1/a.jsp";    RequestDispatcher rd = request.getQRequestDispatcher(forward); 
重定向时:“/”  表示“http://机器IP:8080/”,而通过request.getContextPath()得到的是:“http://机器IP:8080/Web应用名/”,例如:String str =  request.getContextPath();response.sendRedirect(str + "/s1/a.jsp"); 
“/”在配置文件web.xml中 
   url-mapping中,"/"表示“http://IP地址:8080/Web应用名/” 
Java代码   收藏代码
  1. <welcome-file-list>  
  2.   <welcome-file>/index.jsp</welcome-file>  
  3. </welcome-file-list>  
  4.  在web.xml中 如index.jsp前不加"/" 会被默认加上   



"/"在html,javacsript,css中均表示"http://IP地址:8080" 

根据http://www.iteye.com/topic/718443中的总结 

××总结×× 

    在浏览器端:“/”表示的是一台WEB服务器,“http://机器IP:8080/” 
    在服务器端(请求转发):“/”表示的是一个WEB服务器端的应用,“http://机器IP:8080/Web应用/” 
    在服务器端(重定向):“/”表示的是一个WEB服务器,“http://机器IP:8080/” 

sevlet在服务器端,而jsp是由servlet编译的,html,javacsript,css均在浏览器端。 
其中jsp是怎样确定路径的,暂时不清楚 

(转自: http://chenchangqun11.iteye.com/blog/831530)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值