<%@ 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");            
            //写SQL语句
            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>