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

    <%--
      Created by IntelliJ IDEA.
      User: Dell
      Date: 2021/4/11
      Time: 21:44
      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 language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%@ page import="java.sql.*" %>
    <%
    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 'dologin.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>
       
        <%
            String Name = request.getParameter("user");  //获取输入的用户名
            String ps = request.getParameter("password");  // 密码
            String code = request.getParameter("code");   //验证码
            Name.trim();  //去空格
            ps.trim();
             
             
            PreparedStatement pre = null;
            Connection con =null;
            Statement sql;
            ResultSet rs; 
            request.setCharacterEncoding("utf-8");
             
            try{
                Class.forName("com.mysql.jdbc.Driver");
            }catch(Exception e){
                out.print("<h1>加载错误"+e);
            }
             
             
            String user = "root";
            String password="root";
         
             
            con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test",user,password);
                 
                 
            try{
                sql = con.createStatement();
                 
                String SQLL = "select * from user where uname=? and upwd=?";
                pre=con.prepareStatement(SQLL);
                pre.setString(1,Name);
                pre.setString(2,ps);
                 
                 
                rs = pre.executeQuery();
                 
                if(rs.next()){
                    String na = rs.getString(2);
                    session.setAttribute("uname",na);
                    response.sendRedirect("welcome.jsp");
                     
                     
                }else{
                %>
                <script >         //弹窗提示
                alert('输入密码或用户名错误');
                </script>
                <%
                    response.sendRedirect("index.jsp");
                }          
            }catch(SQLException e){
                out.print("<h1>查询错误"+e);
            }
             
                 
             
            %>
       </body>
    </html>
    <<%@ 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 'welcome.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.getAttribute("uname") %></body>
    </html>

  • 相关阅读:
    深入理解计算机系统(3.2)---数据格式、访问信息以及操作数指示符
    深入理解计算机系统(3.1)---走进汇编的世界
    linux下的usb抓包方法
    Linux中查看系统资源占用情况的命令
    中药介绍
    shell中的for循环用法详解
    Linux上shell脚本date的用法
    linux下的shell运算(加、减、乘、除)
    [linux time命令学习篇] time 统计命令执行的时间
    一文简述多种强化学习算法,重要概念和术语一览
  • 原文地址:https://www.cnblogs.com/zhangbowen123/p/14645728.html
Copyright © 2011-2022 走看看