简单登陆,注册的动态网页
登陆页 login.jsp
<%@ 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 uid = document.getElementById("userid"); if(uid.value =="") { alert("请输入用户名"); return false; } if(dlform.password.value == "") { alert("密码不能为空") return false; } return true; } </script> </head> <body> <form id="dlform" action="yanzheng.jsp" method="post" onSubmit="return check();"> 用户名:<input id="userid" name="userid" type="text" value="请输入用户名" size="20"/> 密码:<input id="password" name="password" type="password" size="20"/> <input type="submit" value="登陆" /> <a href="zhuce.jsp">注册新用户</a> </form> </body> </html>
登陆验证页 yanzheng.jsp
<%@ 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 userid = request.getParameter("userid"); String password = request.getParameter("password"); /* if(userid == null || userid.trim().length() == 0) { response.sendRedirect("cuowutishi.jsp?msgid=1"); } else if(password == null || password.trim().length() == 0) { response.sendRedirect("cuowutishi.jsp?msgid=2"); } else { */ //查找用户信息 Object user = application.getAttribute("userxinxi"); String[] zcuser = user.toString().split("#") ; String zcuserid = zcuser[0]; String zcusername = zcuser[1]; String zcpassword = zcuser[2]; if(userid.equals(zcuserid)) { if(password.equals(zcpassword)) { out.print("欢迎" + zcusername + "登陆成功"); //跳转到系统页面 } else { response.sendRedirect("cuowutishi.jsp?msgid=3"); } } else { response.sendRedirect("cuowutishi.jsp?msgid=4"); } //} %> </body> </html>
注册页面 zhuce.jsp
<%@ 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() { if(zcform.zcid.value == "") { alert("请输入用户名"); return false; } if(zcform.zcname.value == "") { alert("请输入用户昵称"); return false; } if(zcform.zcpassword.value == "") { alert("请输入密码"); return false; } if(zcform.qrpassword.value == "") { alert("请输入确认密码"); return false; } if(zcform.qrpassword.value !== zcform.zcpassword.value) { alert("确认密码与用户密码不一致"); return false; } return true; } </script> </head> <body> <form id= "zcform" action="saveUser.jsp" method="get" onsubmit="return check();"> 用户代码:<input id="zcid" name="userid" type="text" size="20" /><br><br> 用户名称:<input id="zcname" name="username" type="text" size="20" /><br><br> 用户密码:<input id="zcpassword" name="password" type="password" size="20" /><br><br> 确认密码:<input id="qrpassword" name="qrpassword" type="password" size="20" /><br><br> <input type="submit" value="提交" /><br> <a href="login.jsp">返回登陆页</a> </form> </body> </html>
保存注册信息页面 saveUser.jsp
<%@ 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 userid = request.getParameter("userid"); String username = new String(request.getParameter("username").getBytes("ISO-8859-1"),"UTF-8"); String password = request.getParameter("password"); /* if(userid == null || userid.trim().length() == 0) { response.sendRedirect("cuowutishi.jsp?msgid=1"); } else if(password == null || password.trim().length() == 0) { response.sendRedirect("cuowutishi.jsp?msgid=2"); } else if(username == null || username.trim().length() == 0) { response.sendRedirect("cuowutishi.jsp?msgid=5"); } else { */ Object user = application.getAttribute("userxinxi"); if(user != null) { response.sendRedirect("cuowutishi.jsp?msgid=7"); } else { String userxinxi = userid + "#" + username + "#" + password; application.setAttribute("userxinxi", userxinxi); response.sendRedirect("cuowutishi.jsp?msgid=6"); } //} %> </body> </html>
错误提示页面 cuowutishi.jsp
<%@ 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("无法识别传递的信息"); break; } } response.setHeader("refresh", "3;URL=login.jsp"); %> </body> </html>