session(练习)
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <form action="text4.jsp" method="post" > 11 <input type="text" name="name"> 12 <input type="submit" value="登录"> 13 </form> 14 </body> 15 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <% 11 String str =new String (request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8"); 12 session.setAttribute("aaa", str); 13 %> 14 添加了session 15 <br> 16 正在等待跳转... 17 <%response.setHeader("refresh","5;URL=test5.jsp"); %> 18 </body> 19 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <% 11 String str=session.getAttribute("aaa").toString(); 12 out.print("用户名="+str); 13 %> 14 </body> 15 </html>
题目:制作登录界面,登录成功后把用户名放在session里,在第3个页面读取session显示用户名




浙公网安备 33010602011771号