jsp1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>session测试</title>
</head>
<body>
<form method="post" name="form">
<table>
<tr>
<td>
用户名:<input type="text" name="user">
</td>
</tr>
</table>
</form>
<%
String user=request.getParameter("user");
session.setAttribute("user",user);
%>
</body>
</html>
jsp2
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.lang.Math"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>admin</title>
</head>
<body>
<form method="post" name="form">
<table>
<tr>
<td>
物品名称:<input type="text" name="user">
</td>
</tr>
</table>
<%
String user=request.getParameter("user");
session.setAttribute("name",user);
%>
</form>
</body>
</html>
jsp3
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.lang.Math"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>static</title>
</head>
<body>
<form method="post" name="form">
<table>
<tr>
<td>
<input type="submit" name="submit" value="下单">
</td>
</tr>
</table>
用户名:<%=session.getAttribute("user") %><br>
商品名称:<%=session.getAttribute("name") %>
</body>
</html>
三个页面为独立的页面,彼此不传递数据
1和2都将数据存储到session中
3读取session中的数据
运行截图
1
2
3