index.jsp
<head>
    <title>My JSP 'index.jsp' starting page</title>
     <script type="text/javascript">
         function myCheck()
         {
            if(form1.name.value=="")
            {
               alert("请输入用户名!");
            }
            if(form1.password.value=="")
            {
               alert("请输入密码!");
            }
            if(form1.check.value=="")
            {
               alert("请输入验证码!");
            }
            if(form1.check.value!=form1.checkAnswer.value)
            {
               alert("验证码不正确!");
            }
         }
      </script>
  </head>
  
  <body>
   <form action="check.jsp" method="post" name="form1">
     <table align="center">
        <tr>
           <td>用户名:</td>
           <td><input type="text" name="name" onMouseOut="this.background='green';">
           </td>
        </tr>
        <tr>
           <td>密  码:</td>
           <td><input type="password" name="password">
           </td>
        </tr>
        <tr>
           <td>验证码:</td>
           <td>
              <input type="text" name="check">
               <%int intmethod=(int)(Math.random()*10);
                 int intmethod2=(int)(Math.random()*10);
                 int intmethod3=(int)(Math.random()*10);
                 int intmethod4=(int)(Math.random()*10);
                 String intsum=intmethod+""+intmethod2+""+intmethod3+""+intmethod4;%>
                 <input type="hidden" name="checkAnswer" value="<%=intsum %>">
           </td>
           <td>
              <span ><img  src="number/<%=intmethod %>.jpg" height="20px">
                       <img  src="number/<%=intmethod2 %>.jpg" height="20px">
                       <img  src="number/<%=intmethod3 %>.jpg" height="20px">
                       <img  src="number/<%=intmethod4 %>.jpg" height="20px">
                 </span>
           </td>
        </tr>
        <tr>
           <td></td>
           <td>
              <input type="submit" value="提交" name="submit" onClick="myCheck()">
              <input type="reset" value="重置" name="submit2">
           </td>
        </tr>
     </table>
   </form>
  </body>
check.jsp<body>
   
      <%
         String name=request.getParameter("name");
         String password=request.getParameter("password");
         String message;
         if(name.equals("min")&&(password.equals("123456")))
         {
            message="欢迎登陆系统";
         }
         else
         {
            message="用户名或密码错误";
         }
       %>
       <script type="text/javascript">
          alert(<%=message%>);
          window.location.href="index.jsp";
       </script>
  </body>