jsp跳轉(zhuǎn)中絕對路徑和相對路徑的解決辦法(來源:csdn)
為了避免jsp跳jsp,servlet跳jsp,forward方式跳轉(zhuǎn),sendRedirect跳轉(zhuǎn)產(chǎn)生的路徑問題,對于jsp和使用sendRedirect跳轉(zhuǎn)的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跳轉(zhuǎn)的servlet,則不要加容器路徑,否則就重復(fù)出現(xiàn) 容器路徑,
posted on 2005-08-25 14:48 幸福是把溫暖的槍 閱讀(1904) 評論(1) 編輯 收藏 所屬分類: java