jsp内置对象作业3-application用户注册
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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话