Servlet(11)—客户端跳转和服务端跳转

客户端跳转:

1、链接跳转:< a href=””>< /a >

2、表单提交< form>< /form>

3、Response.sendRedirect(“3.jsp”);

4、< mata http-equiv=”refresh”, content=”3;2.jsp”/ >

5、response.setHeader(“refresh”,” 3;2.jsp”);

6、客户端跳转“/”代表站点根路径webapp,即http://localhost:8080

服务端跳转:
1、< jsp:forward page=””/>

2、pageContext.forward();

3、 request.getRequestDispatcher(“1.jsp”).forward(request,response);

4、服务器端跳转“/”代表web应用根路径,即:http://localhost:8080/Demo/

注意:使用时如果要使用相对路径时,只有在客户端跳转时加上${pageContext.request.contextPath },该值为web应用的名称。

另外
http://localhost:8080/Demo09_Filter/demo6/articles.jsp
request.getContextPath():表示web应用的名称,如/Demo09_Filter
request.getServletPath():表示的是url地址栏中web应用名称之后的地址/demo6/articles.jsp

原文地址:https://www.cnblogs.com/tengpengfei/p/10453984.html