zoukankan      html  css  js  c++  java
  • 第六周JSP作业:视频6-8的登录功能实现

    <%@ 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=ISO-8859-1">
    <title>登录页面</title>
      <style type="text/css">
       body{font-size:16px};
      </style>
      <script type="text/javascript">
       function mycheck(){
           if(form1.userName.value==""){
               alert("用户名不能为空,请输入用户名!");
               form1.userName.fouse();
               return;
           }
           if(form1.password.value==""){
               alert("密码不能为空,请输入密码!");
               form1.password.fouse();
               return;
           }
           if(form1.validationCode.value==""){
               alert("验证码不能为空,请输入验证码!");
               form1.validationCode.fouse();
               return;
           }
           if(form1.validationCode.value!=form1.validationCode1.value){
               alert("请输入正确的验证码!");
               form1.validationCode.fouse();
               return;
           }
           form1.submit();
       }
      </script>
    </head>
       <body bgcolor="pink">
        <form action="loginCheck.jsp" name="form1" method="post">
              用户名: <input type="text" name="userName" size="16">
          <br>&nbsp;&nbsp;&nbsp;&nbsp;码:  <input type="password" name="password"size="17">
          <br>
              验证码: <input type="text" name="validationCode" onKeyDown="if(event.keyCode==13){form1.submit.focus();}"size="6">
          <%
           int intmethod1=(int)((((Math.random())*11))-1);
           int intmethod2=(int)((((Math.random())*11))-1);
           int intmethod3=(int)((((Math.random())*11))-1);
           int intmethod4=(int)((((Math.random())*11))-1);  
           String intsum=intmethod1+""+intmethod2+intmethod3+intmethod4;
          %>
          <input type="hidden" name="validationCode1" value="<%=intsum%>">
          <input type="text" value="<%=intsum%>" readonly="true" size=2>
          <br>
          <input type="button" name="submit1" value="登录"    onClick="mycheck()">
          &nbsp;
          <input type="reset" 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=ISO-8859-1">
    <title>处理登录页面的数据</title>
    </head>
    <body bgcolor="pink">
     <%
       request.setCharacterEncoding("utf-8");
       String name=request.getParameter("userName");
       String password=request.getParameter("password");
       if(request.getParameter("validationCode1").equals(request.getParameter("validationCode")))
       {
           if(name.equals("lijing")&&(password.equals("666666"))){
               session.setAttribute("userName",name);
               response.sendRedirect("main.jsp");
           }else{
               response.sendRedirect("login.jsp");
             }
           }else{
               response.sendRedirect("login.jsp");
           }
     %>    
    </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=ISO-8859-1">
    <title>系统主页面</title>
    </head>
    <body bgcolor="pink">
     <%
     String name=(String)session.getAttribute("userName");
      %>
      您好<%=name%>,欢迎您访问!<br>
      <a href="exit.jsp">[退出系统]</a>
    </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=ISO-8859-1">
    <title>退出系统</title>
    </head>
    <body>
     <%
      session.invalidate();
     response.sendRedirect("login.jsp");
     %>
    </body>
    </html>

        

     

  • 相关阅读:
    无线鼠标和无线键盘能不能唤醒睡眠中的电脑的解决方案
    教你如何设置同时上内外网(单网卡或双网卡)
    Oracle_字符集问题(数据库与客户端字符集关联关系)
    关于破解移动宽带光猫 型号: GS3101 超级管理员密码
    Oracle 低版本客户端连接 18c 报ORA-28040 和 ORA-01017 错误的解决方法
    sql语句分组统计出年月日下数据记录数目
    Servlet文件上传
    ActiveMq+zookeeper+levelDB集群整合配置
    mongodb 级联操作查询时,关联条件
    maven插件地址博客园
  • 原文地址:https://www.cnblogs.com/lj1221/p/12703513.html
Copyright © 2011-2022 走看看