zoukankan      html  css  js  c++  java
  • 第六周jsp

    index界面

    <%@ 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

    <%@ 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>
    

      success

    <%@ 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>
    

      

  • 相关阅读:
    mysql基础知识
    spring-jdbcTemplet 连接数据源(基础)
    mybatis-----的延迟加载-----缓存(一级缓存和二级缓存)
    第一次使用 idea,mybatis 获取 数据库 中的 数据 2017-9-14
    初识过滤器
    使用 Commens-FileUpload 组件实现文件上传
    简单 servlet 的使用
    QQ数据库管理-----mysql
    mysql 的使用
    json 解析
  • 原文地址:https://www.cnblogs.com/baigei/p/14647486.html
Copyright © 2011-2022 走看看