实战内容:
编写一个JSP页面,将用户名和密码存放到会话中(假设用户名为“孤独求败”,密码为“123456”),再重新定向到另一个JSP页面,将会话中存放的用户名和密码显示出来。(提示:使用response对象的sendRedirect()方法进行重定向)
注意:代码中response.sendRedirect("p4.2.1.jsp"); 的p4.2.1.jsp对应另一个代码的jsp名称
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
session.setAttribute("username","孤独求败");
session.setAttribute("password","123456");
response.sendRedirect("p4.2.1.jsp");
%>
</body>
</html>
p4.2.1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
String username=(String )session.getAttribute("username");
String password=(String )session.getAttribute("password");
%>
用户名:<%=username%><br>
密码:<%=password%>
</body>
</html>
展示效果: