1,注册页面 zhuCe.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 4 <%@ page import = "java.util.*" %> 5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 6 <html> 7 <head> 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9 <title>注册</title> 10 11 <script type="text/javascript"> 12 13 function zx() 14 { 15 window.location.href = "zhuXiao.jsp"; 16 } 17 18 </script> 19 </head> 20 <body> 21 <%! 22 /* 23 public void zx() 24 { 25 this.getServletContext().removeAttribute("zc"); 26 } 27 */ 28 %> 29 30 <% 31 Object obj =application.getAttribute("zc"); 32 33 if(obj == null) 34 { 35 %> 36 请注册:<br> 37 <form action="zccl.jsp" name = "zhc"> 38 用户名: 39 <input type = "text" name = "yhm"><br> 40 密码: 41 <input type ="password" name = "mm"><br> 42 43 <input type ="submit" value="提交"> 44 </form> 45 <% 46 }else{ 47 out.print("欢迎再次光临,用户:" + obj.toString().split("#")[1]); 48 49 %> 50 51 <br> 52 <input type="button" value = "注销" onclick="zx()"> 53 <%} %> 54 55 </body> 56 </html>
2,注册处理页 zccl.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 String yhm = request.getParameter("yhm"); 12 String mm = request.getParameter("mm"); 13 14 if(yhm.equals("") || mm.equals("")) 15 { 16 out.print("用户名及密码不能为空"); 17 18 } 19 else 20 { 21 application.setAttribute("zc", yhm + "#" + mm); 22 out.print("注册成功"); 23 } 24 25 response.setHeader("refresh","3; URL =zhuCe.jsp"); 26 %> 27 </body> 28 </html>
3.注销处理 zhuXiao.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 application.removeAttribute("zc"); 12 response.sendRedirect("zhuCe.jsp"); 13 %> 14 </body> 15 </html>
时间: 2024-10-06 07:37:29