zoukankan      html  css  js  c++  java
  • 第六周JSP作业

    1.login.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        <style type="text/css">
        body{font-size:16px;}
        </style>
        <script type="text/javascript">
        function mycheck(){
        if(form1.userName.value==""){
        alert("用户名不能为空,请输入用户名");
        form1.userName.focuse();
        return;
        }
        if(form1.password.value==""){
        alert("密码不能为空,请输入密码");
        form1.password.focus();
        return;
        }
        if(form1.validationCode.value==""){
        alert("验证码不能为空,请输入验证码");
        form1.validationCode.focus();
        return;
        }
        if(form1.validationCode.value!=form1.validationCode1.value){
        alert("请输入正确的验证码");
        form1.validationCode.focus();
        return;
        }
        form1.submit1();
        }
        </script>
      </head>
      
      <body bgcolor="pink">
       <form action="loginCheck.jsp" name="form1" method="post">
       用户名:<input type="text" name="userName" size="24"><br>&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="password" size="24"><br>
       验证码:<input type="text" name="validationCode" onKeyDown="if(event.keyCode==13){form1.submit.focus();}"size="4">
      <%
      int intmethod1=(int)((((Math.random())*5))+1);
      int intmethod2=(int)((((Math.random())*5))+1);
      int intmethod3=(int)((((Math.random())*5))+1);
      int intmethod4=(int)((((Math.random())*5))+1);
      
      String intsum=intmethod1+""+intmethod2+intmethod3+intmethod4;
       %> 
       <input type="hidden" name="validationCode1" value="<%=intsum%>">
       <img style="height:20px;weight:20px" src="<%=intmethod1 %>.png">
       <img style="height:20px;weight:20px" src="<%=intmethod2 %>.png">
       <img style="height:20px;weight:20px" src="<%=intmethod3 %>.png">
       <img style="height:20px;weight:20px" src="<%=intmethod4 %>.png">
       <br>
       <br>
       <input type="submit" name="submit1" value="登录" onClick="mycheck()">
       &nbsp;
       <input type="reset" value="重置">
       </form>
        
         <br>
      </body>
    </html>

    2.loginCheck.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        
      </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("xiaojunzi")&&(password.equals("123456"))){
      session.setAttribute("userName", name);
      response.sendRedirect("main.jsp");
      }else{
      response.sendRedirect("login.jsp");
      }
      }else{
      response.sendRedirect("login.jsp");
      }
       %>
    
         <br>
      </body>
    </html>

    3.main.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        
      </head>
      
      <body  bgcolor="pink">
      <%
     String name=(String)session.getAttribute("userName");
       %>
    您好<%=name %>,欢迎您访问<br>
    <a href="exit.jsp">【退出系统】</a>
         <br>
      </body>
    </html>

    exit.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        
      </head>
      
      <body>
      <%
    session.invalidate();
    response.sendRedirect("login.jsp");
       %>
         <br>
      </body>
    </html>

    5.图片

  • 相关阅读:
    【LeetCode-动态规划】编辑代价
    【C++】使用istringstream分割字符串
    【LeetCode-字符串】简化路径
    【LeetCode-字符串】简化路径
    【LeetCode-并查集】朋友圈
    【LeetCode-背包】目标和
    【LeetCode-动态规划】分割等和子集
    The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes
    【错误解决】本地计算机上的mysql服务启动停止后,某些服务在未由其他服务或程序使用时将自动停止
    MySQL解压版安装配置详解
  • 原文地址:https://www.cnblogs.com/lixiaoai/p/12698130.html
Copyright © 2011-2022 走看看