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

    <%--
      Created by IntelliJ IDEA.
      User: Dell
      Date: 2021/4/10
      Time: 14:34
      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>
    <form action="dologin.jsp" method="post">
        用户名:<input type="text" name="username"/><br/>
        密码:<input type="password" name="password"/><br/>
        验证码:<input type="text" name="inputVcode"/><img src="/WebProject_war_exploded/createCode"><br/>
        <input type="submit" value="登录">
    </form>
    </body>
    </html>
    <%@ 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>
    <%--
      Created by IntelliJ IDEA.
      User: Dell
      Date: 2021/4/10
      Time: 15:20
      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 username =(String) session.getAttribute("username");
    
        if(username==null){
            response.sendRedirect("login.jsp");
        }
    %>
    欢迎你<%=username %>
    </body>
    </html>
    <%--
      Created by IntelliJ IDEA.
      User: Dell
      Date: 2021/4/10
      Time: 15:20
      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 username =(String) session.getAttribute("username");
    
        if(username==null){
            response.sendRedirect("login.jsp");
        }
    %>
    欢迎你<%=username %>
    </body>
    </html>

    <%--
      Created by IntelliJ IDEA.
      User: Dell
      Date: 2021/4/10
      Time: 14:34
      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>
    <form action="dologin.jsp" method="post">
        用户名:<input type="text" name="username"/><br/>
        密码:<input type="password" name="password"/><br/>
        验证码:<input type="text" name="inputVcode"/><img src="/WebProject_war_exploded/createCode"><br/>
        <input type="submit" value="登录">
    </form>
    </body>
    </html>
  • 相关阅读:
    wpf学习笔记StackPanel
    wpf学习笔记DockPanel
    wpf学习笔记Viewbox
    C#.NET 中的类型转换
    超简单U盘PE启动完全攻略(U盘上仅四个文件)
    Web 应用的 UML 建模与 .NET 框架开发
    100多个很有用的JavaScript函数以及基础写法大集合
    Asp.net(C#)显示所有缓存 清除所有缓存
    grub引导U盘(集成常用工具/深山红叶PE工具箱V30/完美者U盘维护系统V8.1)
    GRUB启动命令详解
  • 原文地址:https://www.cnblogs.com/guoyongqi-blog/p/14672446.html
Copyright © 2011-2022 走看看