JSP第六周 还是session

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
     <script type="text/javascript">
         function myCheck(){
            if(form1.username.value==""){
            alert("账号不能为空");
            form1.username.focus();
            return;
            }
            if(form1.username.value!="admin"){
            alert("账号输入错误");
            form1.username.focus();
            return;
            }
            if(form1.pwd.value==""){
            alert("密码不能为空");
            form1.pwd.focus();
            return;
            }
            if(form1.pwd.value!="123456"){
            alert("密码输入错误");
            form1.pwd.focus();
            return;
            }
            if(form1.yzm.value==""){
            alert("验证码不能为空");
            form1.yzm.focus();
            return;
            }
            if(form1.yzm.value!=form1.mlgb.value){
            alert("请输入正确的验证码");
            form1.yzm.focus();
            return;
            }
            form1.submit1();
         }
     </script>
  
    
   

  </head>
  
  <body>
  
        <form action="sf7.jsp" method="post" name="form1">
             用户名:<input type="text" name="username" ><br><br>
             密   码:<input type="password" name="pwd"><br><br>
             验证码:<input type="password" name="yzm" size="6">  <br><br>
         
    
        
        
        <% 
        //产生随机数并连接
           int yzm1=(int)  ( ( (Math.random())*11  )   -1    );
            int yzm2=(int)  ( ( (Math.random())*11  )   -1    );
             int yzm3=(int)  ( ( (Math.random())*11  )   -1    );
              int yzm4=(int)  ( ( (Math.random())*11  )   -1    );
              String yzmSum=yzm1+""+yzm2+yzm3+yzm4;
   
         %>
         
           <!-- 设置隐藏域 验证时候比较 -->
           <input type="hidden" name="mlgb" value=<%=yzmSum %>>
           
           <img src="img/<%=yzm1%>.gif">
           <img src="img/<%=yzm2%>.gif">
           <img src="img/<%=yzm3%>.gif">
           <img src="img/<%=yzm4%>.gif">
           <hr>
                  <input type="submit" value="登录" name="submit1" onClick="myCheck()"> 
                  <input type="reset" value="重置">
  
                      </form>
                      
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
 
  

   

  </head>
  
  <body>
           <% 
            String username=request.getParameter("username");
             session.setAttribute("username", username);
            String pwd=request.getParameter("pwd");
            String  yzm=request.getParameter("yzm");
            String mlgb=request.getParameter("mlgb");
            if( username.equals("admin")&&pwd.equals("123456")&&yzm.equals(mlgb) ){
               
               request.getRequestDispatcher("main.jsp").forward(request, response);
            }else{
                response.sendRedirect("sf6.jsp");
            }
           
           
           
            %>
    
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>


  </head>
  
  <body>
         <%     String username=(String)session.getAttribute("username");
     
               
          %>
   
             <%=username %> 欢迎你来到  CCTV  <br><br>
             <hr>
             <a href="exit.jsp">退出系统</a>
             <%   %>
             
             
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>


  </head>
  
  <body>
  

    <% session.invalidate();
       response.sendRedirect("sf6.jsp")  ;  
     %>
  </body>
</html>

  

posted @ 2020-04-11 21:11  郭少锋18840631471  阅读(132)  评论(0编辑  收藏  举报