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>

 

转载于:https://www.cnblogs.com/dirgo/p/4994129.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值