`
寻梦者
  • 浏览: 627207 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

JavaWeb中的“/”

阅读更多

 

       1. 在 超链接 href 属性表单的 action 属性中的 "/" 代表 web 站点的根目录: http://localhost:8080/

       2. 在 response.sendRedirect() 方法参数中的 "/" 也代表 web 站点的根目录: http://localhost:8080/, 因为该方法实际上就是一个自动的超链接

       3. request.getRequestDispatcher() 方法参数中的 "/" 代表当前 web 应用的根目录,因为该方法只能访问当前 web 应用下的资源所以 "/" 代表当前 web 应用的根目录

      4. <c:url value='' /> 标签中 value 属性值以及 <c:redirect url=""> 中的 url 属性 中  "/" 代表当前 web 应用的根目录因为它们是 JSTL 标签 而 JSTL 是为当前 web 应用定制的标签所以 "/" 代表当前 web 应用的根目录实际上 JSTL 中的带地址的标签中的 "/" 都是如此.

    5.web.xml配置文件中<url-mapping>标签里面的前置路径是web应用的根目录

    6.jsp页面中,<base>标签来确定请求的跟路径(请看下面代码),如果没有则以当前页面的路径为标准:

 

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>"> 
  </head>

 

     7.在请求中,我们往往需要获取全路径来确保页面定位,如下代码所示:

      

${pageContext.request.contextPath} 

 

    利用EL表达式,相当于http://localhost:8080/应用名称

    其在java类中的实现代码如下:

   

String path = request.getScheme()   
                    +"://"  
                    + request.getServerName()   
                    + ":" + request.getServerPort()   
                    + request.getContextPath()  

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics