zoukankan      html  css  js  c++  java
  • 用户注册,登录,留言系统

    1, 登录页面

     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 <script type="text/javascript">
     9 function check()              //函数检查登录框内的内容不能为空
    10 {
    11     var uid = document.getElementById("userid");         //获得id=userid的document
    12     if (uid.value == "")
    13         {
    14             alert("用户代码不能为空");
    15             return false;
    16         }
    17     if (uform.password.value == "")
    18         {
    19             alert("密码不能为空");
    20             return false;
    21         }
    22     return true;
    23 }
    24 </script>
    25 </head>
    26 <body>
    27 <form id="uform" action="yanzheng.jsp" method="post"  onSubmit="return check();" >
    28 用户代码:<input id="userid" type="text" name="userid" width=30 />
    29 密码:<input id="password" type="password" name="password" width=30 />
    30 <input type="submit" value="登录" />
    31 <a href="zhuce.jsp" >注册新用户</a>
    32 </form>
    33 </body>
    34 </html>

    2, 注册页面

     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 <script type="text/javascript">
     9 function check()                    //函数检查注册帐号的内容不能为空
    10 {
    11     var uid = document.getElementById("userid");
    12     if (uid.value == "")
    13         {
    14             alert("用户代码不能为空");
    15             return false;
    16         }
    17     if (uform.username.value == "")
    18         {
    19             alert("用户名称不能为空");
    20             return false;
    21         }
    22     if (uform.password.value == "")
    23         {
    24             alert("密码不能为空");
    25             return false;
    26         }
    27     if (uform.password.value != uform.queren.value)
    28         {
    29             alert("登录密码和确认密码不一致");
    30             return false;
    31         }
    32     return true;
    33 }
    34 </script>
    35 </head>
    36 <body>
    37 <form id="uform" action="saveUser.jsp"  onSubmit="return check();">
    38 用户代码:<input id="userid" type="text" name="userid" width=30 />
    39 <br><br>
    40 用户名称:<input id="username" type="text" name="username" width=30 />
    41 <br><br>
    42 登录密码:<input id="password" type="password" name="password" width=30 />
    43 <br><br>
    44 确认密码:<input id="queren" type="password" name="queren" width=30 />
    45 <br><br>
    46 <input type="submit" value="提交" />
    47 </form>
    48 </body>
    49 </html>

    3, 保存注册的信息

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <%@page import="com.hanqi.*" %>
     4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     5 <html>
     6 <head>
     7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     8 <title>保存用户信息</title>
     9 </head>
    10 <body>
    11 <%
    12 String strUserid = request.getParameter("userid");
    13 String strUsername = request.getParameter("username");
    14 String strPW = request.getParameter("password");                //获取注册的信息
    15 if (strUserid == null || strUserid.trim().length() == 0)           
    16     {
    17         response.sendRedirect("message.jsp?msgid=1");
    18     }
    19 else if (strUsername == null || strUsername.trim().length() == 0)
    20     {
    21         response.sendRedirect("message.jsp?msgid=5");
    22     }
    23 else if (strPW == null || strPW.trim().length() == 0)
    24     {
    25         response.sendRedirect("message.jsp?msgid=2");
    26     }
    27 else
    28     {
    29         //查找用户信息
    30         Object obj = application.getAttribute(strUserid);
    31         if (obj != null)
    32             {
    33                 response.sendRedirect("message.jsp?msgid=7");
    34             }
    35         else
    36             {
    37                 strUsername = new String(strUsername.getBytes("ISO-8859-1"),"UTF-8");             //将获取到的值进行转码
    38                 String strUser = strUserid + "#" + strUsername + "#" + strPW;          //将获取到的值组合成一个字符串并储存起来
    44                 application.setAttribute(strUserid, strUser);               //设置application的属性值
    45                 response.sendRedirect("message.jsp?msgid=6");
    46             }
    47     }
    48 %>
    49 </body>
    50 </html>

    4, 验证登陆的帐号

     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 strUserid = request.getParameter("userid");         //获取登录页面的信息并验证
    12 String strPW = request.getParameter("password");
    13 if (strUserid == null || strUserid.trim().length() == 0)
    14     {
    15         response.sendRedirect("message.jsp?msgid=1");
    16     }
    17 else if (strPW == null || strPW.trim().length() == 0)
    18     {
    19         response.sendRedirect("message.jsp?msgid=2");
    20     }
    21 else
    22     {
    23         //查找用户信息, 若已经存在则输出信息
    24         Object obj = application.getAttribute(strUserid);
    25             if (obj != null)
    26                 {
    27                     String strUser = obj.toString();           //将获取的application的值
    28                     String[] user = strUser.split("#");            //将组合的字符串分割,分别赋值
    29                     String strUID = user[0];
    30                     String strUsername = user[1];
    31                     String strP = user[2];
    32                         if(strPW.equals(strP))                 
    33                             {
    34                                 out.print("欢迎 " + strUsername + " 登录系统");
    35                                 //跳转到系统页面
    36                                 session.setAttribute("login", strUsername);
    37                             }
    38                         else
    39                             {
    40                                 response.sendRedirect("message.jsp?msgid=3");
    41                             }
    42                 }
    43             else
    44                 {
    45                     response.sendRedirect("message.jsp?msgid=4");
    46                 }
    47     }
    48 %>
    49 <br><br>
    50 <a href="liuyan.jsp" >留言簿</a>
    51 </body>
    52 </html>

    5, 留言簿界面

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <%@ page import="java.util.*"%>
     4 <%@ page import="java.text.*" %>
     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 String userName = "";
    12 
    13 //检查登录状态
    14 Object o = session.getAttribute("login");        //检查在验证登陆帐号的页面的session对象,利用其特点防止跳过登录页面
    15 if (o == null)
    16     {
    17         response.sendRedirect("message.jsp?msgid=8");
    18     }
    19 else
    20     {
    21         userName = o.toString();
    22     }
    23 String liuy = request.getParameter("liuy");
    24 if (liuy != null && !liuy.equals(""))
    25     {
    26         String strLiuy = new String(liuy.getBytes("ISO-8859-1"), "UTF-8");
    27         //附加时间信息
    28         Date dt = new Date();
    29         //格式化时间
    30         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");         
    31         strLiuy += "&nbsp;&nbsp;&nbsp;&nbsp;    " + sdf.format(dt) + " 留言人:" + userName;
    32         Object obj = application.getAttribute("liuy");
    33         ArrayList<String> A;
    34         if (obj == null)
    35             {
    36                 A = new ArrayList<String>();
    37             }
    38         else
    39             {
    40                 A = (ArrayList<String>) obj;
    41             }
    42         A.add(strLiuy);             //添加留言,存入application
    43         application.setAttribute("liuy", A);
    44     } 
    45 %>
    46 </head>
    47 <body>
    48     <form>             //<form>表单编辑留言
    49         最新留言: <br> <br>
    50         <%
    51             int i = 1;
    52             Object obj = application.getAttribute("liuy");
    53             if (obj != null)
    54             {
    55                 ArrayList<String> A = (ArrayList<String>) obj;         //将留言的内容保存为集合的形式
    56                 for (int m = A.size() - 1; m >= 0; m--)
    57                     {
    58                         out.print(i + ". " + A.get(m) + "<br>");
    59                         i++;
    60                     }
    61             }
    62         %>
    63         <br> <br> <br> 留言内容: <br>
    64         <textarea rows="10" cols="30" name="liuy"></textarea>
    65         <br> <input type=submit value="提交">
    66     </form>
    67 </body>
    68 </html>

    6, 各种错误信息

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3     <%@ page import="java.util.*" %>
     4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     5 <html>
     6 <head>
     7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     8 <title>消息页面</title>
     9 </head>
    10 <body>
    11 <%
    12 String strMsgID = request.getParameter("msgid");
    13 if (strMsgID == null || strMsgID.trim().length() == 0)
    14     {
    15         out.print("请正确传递信息");
    16     }
    17 else
    18     {
    19         int iMsgid = Integer.parseInt(strMsgID);
    20         switch (iMsgid)
    21             {
    22                 case 1:
    23                     out.print("请正确输入用户代码");
    24                     break;
    25                 case 2:
    26                     out.print("请正确输入密码");
    27                     break;
    28                 case 3:
    29                     out.print("密码输入错误");
    30                     break;
    31                 case 4:
    32                     out.print("该用户不存在");
    33                     break;
    34                 case 5:
    35                     out.print("请正确输入用户名称");
    36                     break;
    37                 case 6:
    38                     out.print("提交成功");
    39                     break;
    40                 case 7:
    41                     out.print("用户代码已存在");
    42                     break;
    43                 case 8:
    44                     out.print("请登录系统");
    45                     break;
    46                 default:
    47                     out.print("传递的msgid错误");
    48                     break;
    49             }
    50     }
    51 response.setHeader("refresh", "3;URL=Login.jsp");
    52 %>
    53 </body>
    54 </html>
  • 相关阅读:
    CentOS 7 修改时区
    flink与kafka结合
    Kafka 原理和实战
    kafka单机多节点部署
    使用yumdownloadonly下载RPM包及依赖包
    使用Onvif协议进行设备发现以及指定设备信息探测
    kafka相关脚本操作
    Python入门篇-基础语法
    Python入门篇-pyenv安装及应用
    zabbix Server 4.0监控Flume关键参数
  • 原文地址:https://www.cnblogs.com/wgbs25673578/p/5008635.html
Copyright © 2011-2022 走看看