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

    <%@ 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>
    复制代码
    复制代码
    package com.ee.dao;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    
    import javax.resource.cci.ResultSet;
    
    import com.ee.bean.User;
    
    public class UserDao {
    
        public int addUser(User u){
            int i=0;
            
            try {
             
                Class.forName("com.mysql.jdbc.Driver");
                
                Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8", "root", "12345678");            
                
                String sql="insert into user2(name,password) values(?,?)";            
               
                PreparedStatement ps=con.prepareStatement(sql);
                ps.setString(1, u.getUname());
                ps.setString(2, u.getUpwd());
                i=ps.executeUpdate();
                
                
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return i;
            
                    
        }
        public int selectUser(User u){
            int n=0;
            try{
                Class.forName("com.mysql.jdbc.Driver");
                Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8", "root", "12345678");    
                String sql="select name,password from user2 where name=?and password
    =?";    
                PreparedStatement ps=con.prepareStatement(sql);
                ps.setString(1, u.getUname());
                ps.setString(2, u.getUpwd());
                n=ps.executeUpdate();
                
            } catch (Exception e) {
                e.printStackTrace();
            }
            return n;
            
                    
        }            
    }
     
    复制代码
    <%@page import="com.ee.dao.UserDao"%>
    <%@page import="com.ee.bean.User"%>
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        User u = new User();
        
        String uname = request.getParameter("name");
        u.setUname(uname);
        String upwd = request.getParameter("password");
        u.setUpwd(upwd);
        UserDao ud=new UserDao();
        if(ud.addUser(u)>0){
            
        }else{
          
        }    
    %>
    <%    
        if(uname.equals("zs")&&upwd.equals("123")){
        
        request.getRequestDispatcher("welcome.jsp").forward(request, response);
        session.setAttribute("name",name);
        }
        else{
        
        request.getRequestDispatcher("login.jsp").forward(request, response);
        }
    %>
    复制代码
    
    
    复制代码
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    
    <html>
    <body>
    登录成功
    
    <input type="button" value="点击登录" onclick="window.location = 'reg.jsp';"/>
    
    
    </body>
    </html>
  • 相关阅读:
    mysql显示乱码
    aws常用命令
    Hive分析窗口函数(一) SUM,AVG,MIN,MAX
    Hive函数介绍
    Apache Drill 调研学习
    公有云与私有云对比分析报告
    python3 使用libvirt 相关安装
    libvirt虚拟库
    Reveal CocoaPods的使用
    AFNetworking 2.0 使用
  • 原文地址:https://www.cnblogs.com/SmileMRzhang/p/14675540.html
Copyright © 2011-2022 走看看