在Web中可以使用<jsp:forward>指令,将一个用户的请求(request)从一个页面传递到另外一个页面,即完成跳转的操作。
不传递参数:
<jsp:forward page="{要跳转的页面路径 | <%=表达式%>}" />
传递参数:
<jsp:forward page="{要跳转的页面路径 | <%=表达式%>}">
<jsp:param value="参数内容" name="参数名"/>
...可以向要跳转的页面传递多个参数
</jsp:forward>
【例子】:
forward_demo1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>标题</title>
</head>
<body>
<jsp:forward page="forward_demo2.jsp">
<jsp:param value="zhangsan" name="username" />
<jsp:param value="25" name="age" />
</jsp:forward>
</body>
</html>
forward_demo2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>标题</title>
</head>
<body>
<h2>username = <%=request.getParameter("username") %></h2>
<h2>age = <%=request.getParameter("age") %></h2>
</body>
</html>
网友评论