jsp登录会话
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>登录界面</title> 8 </head> 9 <body> 10 11 <form action="test_session2.jsp" method="post"> 12 <table width="300" height="300" border="0" align="center"> 13 <tr height="80" align="center"> 14 <td colspan="2"><font size="24">OO登录</font></td></tr> 15 <tr height="30"> 16 <td width="80" align="right">用户名:</td> 17 <td><input type="text" name="name"></td></tr> 18 <tr height="30"> 19 <td width="80" align="right"> 密 码:</td> 20 <td> <input type="password" name="password"></td></tr> 21 <tr><td height="40" align="center" colspan="2"> 22 <input type="submit" value="登录"></td></tr> 23 </table> 24 25 26 </body> 27 </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>登录成功</title> 8 </head> 9 <body> 10 <% 11 String name = new String( request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8"); 12 session.setAttribute("name", name); 13 14 out.println(name + "成功登陆"); 15 %>
16 <a href="test_session3.jsp"><br>跳转</a> 17 </body> 18 </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>会话</title> 8 </head> 9 <body> 10 <% 11 String str = ""; 12 Object obj = session.getAttribute("name"); 13 if(obj != null){ 14 str = obj.toString(); 15 out.println(str + "已经成功登陆"); 16 }else{ 17 out.println("会话超时,请重新登录。"); 18 } 19 %> 20 </body> 21 </html>