幸福是把温暖的枪

jsp跳转中绝对路径和相对路径的解决办法(来源:csdn)

 为了避免jsp跳jsp,servlet跳jsp,forward方式跳转,sendRedirect跳转产生的路径问题,
   对于jsp和使用sendRedirect跳转的servlet,采用直接使用带
   容器路径[String request.getContextPath()]的绝对路径就可以彻底解决,即:
    1)<%
          String contextPath = request.getContextPath();
          String url = contextPath + "/user/login.jsp";
       %>
       
       <a href="<%=url%>"> login</a>
   2) ....
      String contextPath = request.getContextPath();
      String targetPath = contextPath + "/user/login.jsp";
      RequestDispatcher rd = request.getRequestDispatcher(targetPath);
      rd.forward(request, response);
      ......

   对于使用forward跳转的servlet,则不要加容器路径,否则就重复出现 容器路径,

posted on 2005-08-25 14:48 幸福是把温暖的枪 阅读(1883) 评论(1)  编辑  收藏 所属分类: java

评论

# re: jsp跳转中绝对路径和相对路径的解决办法(来源:csdn) 2008-05-15 15:35 d

这种方法不可行  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: