Servlet的跳转一样,JSP的跳转也分服务端跳转和客户端跳转。

步骤1:首先准备 jump.jsp 
步骤2:客户端跳转
步骤3:服务端跳转

示例 1 : 首先准备 jump.jsp 

首先准备一个jump.jsp 来分别演示客户端跳转和服务端跳转

示例 2 : 客户端跳转

jsp的客户端跳转和Servlet中是一样的。

response.sendRedirect("hello.jsp");


可以通过firefox的调试工具可以观察到访问jump.jsp返回302(临时客户端跳转),跳转到了hello.jsp

JSP系列教材 (五)- 服务端跳转和客户端跳转

<% 

    response.sendRedirect("hello.jsp");

%>

示例 3 : 服务端跳转

Servlet的服务端跳转一样,也可以使用

request.getRequestDispatcher("hello.jsp").forward(request, response);



或者使用动作,简化代码

<jsp:forward page="hello.jsp"/>

JSP系列教材 (五)- 服务端跳转和客户端跳转

<jsp:forward page="hello.jsp"/>


更多内容,点击了解: https://how2j.cn/k/jsp/jsp-redirect/577.html

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2021-10-22
  • 2022-02-26
  • 2021-12-04
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2021-04-18
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
相关资源
相似解决方案