20151126

<%@ 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="text" name="password"  width=30 />
<br>
<input type="submit" value="提交" /> 
</form>

</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)        //trim()  去掉空格
  {
      response.sendRedirect("massage.jsp?msgid=1");    //跳转到massage.jsp 文件中的 msgid=1
  }  
  else if(strPW ==  null || strPW.trim().length() == 0)        //trim()  去掉空格
  {
      response.sendRedirect("massage.jsp?msgid=2");
  }  
  else
  {
      //查找用户信息
      String strUID = "zhangsan";
      String strP = "123456";
      if (strUserid.equals(strUID))  //找到账户
      {
          if(strPW.equals(strP))
          {
              response.sendRedirect("massage.jsp?msgid=3");
          }
          else
          {
              response.sendRedirect("massage.jsp?msgid=4");
          }
      }
      else
      {
          response.sendRedirect("massage.jsp?msgid=5");
      }
  }
%>
</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)        //当错误信息为1时 输出一句话
        {
        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;
        default:
            out.print("传递的msgid错误");
        }
    }
response.setHeader("refresh","3;URL=login.jsp");
%>
</body>
</html>
消息页面
原文地址:https://www.cnblogs.com/name-hanlin/p/4999278.html