登录页
<%@ 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> <form action="yanzheng.jsp" method="post"> 用户名: <input type="text" name="userid" width="30"/> 密码: <input type="password" name="mima" width="30"/> <input type="submit" value="登录"/> </form> </body> </html>
消息页
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 13 String strMsgID = request.getParameter("msgid"); 14 15 if(strMsgID ==null || strMsgID.trim().length()==0) 16 { 17 out.print("请正确传递信息"); 18 } 19 else 20 { 21 int msgid = Integer.parseInt(strMsgID); 22 23 switch(msgid) 24 { 25 case 1: 26 27 out.print("请正确输入用户名"); 28 29 break; 30 31 case 2: 32 33 out.print("请正确输入密码"); 34 35 break; 36 37 case 3: 38 39 out.print("密码输入错误"); 40 41 break; 42 43 case 4: 44 45 out.print("该用户不存在"); 46 47 break; 48 } 49 } 50 51 response.setHeader("refresh", "3;URL=Login.jsp"); 52 %> 53 </body> 54 </html>
验证页
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 12 String strUserid = request.getParameter("userid"); 13 14 String strPW = request.getParameter("mima"); 15 16 if(strUserid==null||strUserid.trim().length()==0) 17 { 18 response.sendRedirect("message.jsp?msgid=1"); 19 } 20 else if(strPW==null||strPW.trim().length()==0) 21 { 22 response.sendRedirect("message.jsp?msgid=2"); 23 } 24 else 25 { 26 //查找用户信息 27 String strUID="zhangsan"; 28 String strP ="123456"; 29 30 if(strUserid.equals(strUID))//找到 31 { 32 if(strPW.equals(strP)) 33 { 34 out.print("登录成功"); 35 } 36 else 37 { 38 response.sendRedirect("message.jsp?msgid=3"); 39 } 40 } 41 else 42 { 43 response.sendRedirect("message.jsp?msgid=4"); 44 } 45 } 46 %> 47 </body> 48 </html>
原文:http://www.cnblogs.com/zxw0004/p/4999235.html