• jsp第六周作业


    index.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
      <head>
        <title>$Title$</title>
      </head>
     
      <body>
      <form action="dologin.jsp" method="post" >
        用户名:<input type="text" name="username"/>
        <br>
        密码:<input type="password"  name="password"/>
        <br>
        <input type="submit" value="登录">
      </form>
      </body>
    </html>

    login.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>接受密码并验证</title>
    </head>
    <body>
    <%                    
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println(username);
        String rightUsername ="";
        String rightPassword ="";
     
           
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/firsttry", "root", "root");
            PreparedStatement preparedStatement = connection.prepareStatement("select * from jsp where username=?");
            preparedStatement.setString(1, "zhangsan");
            ResultSet resultSet = preparedStatement.executeQuery();
            System.out.println(resultSet);
            while (resultSet.next()) {
                rightUsername = resultSet.getString("username");
                rightPassword = resultSet.getString("userpassword");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
     
     
            if (username.equals(rightUsername) && password.equals(rightPassword)) {
                session.setAttribute("username", username);
                response.sendRedirect("success.jsp");
            } else {
                response.sendRedirect("index.jsp");
            }
     
    %>
    </body>
    </html>

    dologin.jsp

    <%@ page import="java.sql.*" %><%--
      Created by IntelliJ IDEA.
      User: Dell
      Date: 2021/4/10
      Time: 14:38
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <%
        String uname = request.getParameter("username");
        String upwd = request.getParameter("password");
        String inputVcode = request.getParameter("inputVcode").toLowerCase();
        String realInputVcode =(String) session.getAttribute("codes");
    
        String realUname="";
        String reaslPassword = "";
    
        Class.forName("com.mysql.jdbc.Driver");
    
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
    
        PreparedStatement preparedStatement =connection.prepareStatement("SELECT * FROM dl where uname = ?");
        preparedStatement.setString(1,uname);
    
    
        ResultSet rs = null;
        try {
            rs = preparedStatement.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //如果有数据,rs.next()返回true
        while(rs.next()){
           realUname = rs.getString("uname");
           reaslPassword = rs.getString("upwd");
        }
    
        if(uname.equals(realUname)&&upwd.equals(reaslPassword)&&inputVcode.equals(inputVcode)){
            HttpSession httpSession = request.getSession();
            httpSession.setAttribute("username",uname);
            httpSession.setAttribute("password",upwd);
            response.sendRedirect("success.jsp");
        }else {
            response.sendRedirect("login.jsp");
        }
    %>
    </body>
    </html>

    success.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <%
    String username = (String) session.getAttribute("username");
    %>
           恭喜您<%=username%>登录成功
    </body>
    </html>

  • 相关阅读:
    缺陷管理、分类、提交
    selenium2.0处理case实例(二)
    Robot Framework自动化测试(六)--- robotremoteserver使用
    Robot Framework自动化测试(五)--- 开发系统关键字
    Robot Framework自动化测试(四)--- 分层思想
    Robot Framework自动化测试(三)---Selenium API
    Robot Framework自动化测试(二)---元素定位
    Robot Framework自动化测试(一)---第一个脚本
    python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告
    Python 基于http接口自动化测试
  • 原文地址:https://www.cnblogs.com/sigure0428/p/14647914.html
Copyright © 2020-2023  润新知