<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录页</title> <script type="text/javascript"> function check() { var userid = document.getElementById("userid"); if (userid.value == "") { alert("用户代码不可为空!"); return false; } if(uform.password.value == "") { alert("密码不能为空"); return false; } return true; } </script> </head> <body> <form id="uform" action="yanzheng.jsp" method="post" onSubmit="return check();"> 用户代码:<input id="userid" type="text" name="userid" width=30 /> 密码:<input id="password" type="password" name="password" width=30 /> <input type="submit" value="登录" /> <a href="zhuce.jsp" >注册新用户</a> </form> </body> </html>
登录页
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>消息页面</title> </head> <body> <% String strMsgID = request.getParameter("msgid"); if (strMsgID == null || strMsgID.trim().length() == 0) { out.print("请正确传递信息"); } else { int iMsgid = Integer.parseInt(strMsgID); switch (iMsgid) { case 1: out.print("请正确输入用户代码"); break; case 2: out.print("请正确输入密码"); break; case 3: out.print("密码输入错误"); break; case 4: out.print("该用户不存在"); break; case 5: out.print("请正确输入用户名称"); break; case 6: out.print("提交成功"); break; case 7: out.print("用户代码已存在"); break; default: out.print("传递的msgid不认识"); break; } } response.setHeader("refresh", "3;URL=login.jsp"); %> </body> </html>
消息页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录验证页</title> </head> <body> <% String strUserid = request.getParameter("userid"); String strPW = request.getParameter("password"); if (strUserid == null || strUserid.trim().length() == 0) { response.sendRedirect("message.jsp?msgid=1"); } else if (strPW == null || strPW.trim().length() == 0) { response.sendRedirect("message.jsp?msgid=2"); } else { //查找用户信息 Object obj = application.getAttribute(strUserid); if (obj != null) { String strUser = obj.toString(); String[] user = strUser.split("#"); String strUID = user[0]; String strUsername = user[1]; String strP = user[2]; if(strPW.equals(strP)) { out.print("欢迎 " + strUsername + " 登录系统"); } else { response.sendRedirect("message.jsp?msgid=3"); } } else { response.sendRedirect("message.jsp?msgid=4"); } } %> </body> </html>
登录验证页
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>保存用户信息</title> </head> <body> <% String strUserid = request.getParameter("userid"); String strUsername = request.getParameter("username"); String strPW = request.getParameter("password"); if (strUserid == null || strUserid.trim().length() == 0) { response.sendRedirect("message.jsp?msgid=1"); } else if (strUsername == null || strUsername.trim().length() == 0) { response.sendRedirect("message.jsp?msgid=5"); } else if (strPW == null || strPW.trim().length() == 0) { response.sendRedirect("message.jsp?msgid=2"); } else { //查找用户信息 Object obj = application.getAttribute(strUserid); if (obj != null) { response.sendRedirect("message.jsp?msgid=7"); } else { strUsername = new String(strUsername.getBytes("ISO-8859-1"),"UTF-8"); String strUser = strUserid + "#" + strUsername + "#" + strPW; application.setAttribute(strUserid, strUser); response.sendRedirect("message.jsp?msgid=6"); } } %> </body> </html>
保存用户信息
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>用户注册</title> <script type="text/javascript"> function yanz() { if (zhugan.userid.value == "") { alert("用户代码不能为空!"); return false; } if(zhugan.username.value == "") { alert("用户名称不能为空!"); return false; } if(zhugan.password.value == "") { alert("登陆密码不能为空!"); return false; } if(zhugan.passwore.value == "") { alert("确认密码不能为空!"); return false; } if(zhugan.password.value != zhugan.passwore.value) { alert("登陆密码与确认密码不相同!"); return false; } return true; } </script> </head> <body> <form id="zhugan" action="saveUser.jsp" method="post" onSubmit="return yanz();"> 用户代码:<input id="userid" type="text" name="userid" width=30 /> <br><br> 用户名称:<input id="username" type="text" name="username" width=30 /> <br><br> 登录密码:<input id="password" type="password" name="password" width=30 /> <br><br> 确认密码:<input id="passwore" type="password" name="pueren" width=30 /> <br><br> <input type="submit" value="提交" /> </form> </body> </html>
用户注册
时间: 2024-10-23 22:56:12