使用bootstrap
+JavaEE
+JDBC
+JSP
+Ajax
页面;实现一个用户信息的增删改查功能
下载对应版本即可!
- 注册时只对用户名和密码进行正则验证,只输入用户名和密码,直接注册会成功!
- 新增ajax,用户名注册验证,数据库是否存在已经注册的用户账号
- 注册新增,ajax注册,注册可使用表单的post请求和ajax的post请求
- 解决免登陆问题,登录后点击添加用户,再点击登录页面,会一直在注册页面
- 修改展示数据的方式,改为ajax请求
- 新增模糊查询用户账号
- 删除check.jsp和cookie.jsp,采用filter过滤器判断用户是否登录和免登陆
- filter进行传统配置和注解配置混合的方法
用户表(账号,密码,性别,学历,爱好)
create table d_student(
account varchar(50) primary key,
pwd varchar(50) not null,
sex varchar(10) not null,
educ varchar(10) not null,
happy varchar(50) not null
)default charset=utf8;
- 注册,登录,登出
- cookie 30s内免登录
- session防止用户直接输入网站登录
- 查看用户信息,并修改
- 删除用户信息
注意 :本系统可使用任何账号操作所有用户的信息!!!
本数据库配置文件与 src 同级
#通过反射获取获取包
driverClassName=com.mysql.jc.jdbc.Driver #8.0
#driverClassName=com.mysql.jdbc.Driver #5.0 数据库版本
# localhost 本地服务器
# 3306 端口
# demo 数据库名
# &useSSL=false&serverTimezone=UTC 数据库版本5.0左右可去除,我使用的是8.0以上的版本,&作为参数的连接符
url=jdbc:mysql://localhost:3306/demo?characterEncoding=utf8&useSSL=false&serverTimezone=UTC
# 用户名
username=root
# 密码
password=root
使用德鲁伊连接池和QueryRunner处理数据,需要导包
package com.utils;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;
/**
* @author 涂鏊飞[email protected]
* @description: 数据库操作工具类 类描述
* @create 2021-09-01 17:18
*/
public class JdbcUtils {
private static DataSource ds;
static {
try {
//1.加载配置文件
Properties pro = new Properties();
pro.load(JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties"));
//2.获取DataSource
ds = DruidDataSourceFactory.createDataSource(pro);
}
catch (Exception e){
ds = null;
}
}
private static Connection getConnection(){
Connection con;
try {
con = ds.getConnection();
}
catch (Exception ex){
con = null;
}
return con;
}
/* 获取 QueryRunner */
public static QueryRunner getQueryRunner(){
QueryRunner runner = new QueryRunner(ds);
return runner;
}
}
数据库中的表对应的实体类: Student.java
public interface StudentDao
抽象方法
1️⃣ public Integer insertStudent(Student student) throws SQLException;
//插入数据
2️⃣ public List<Student> selectAll() throws SQLException;
// 查询所有用户信息
3️⃣ public Student selectOne(String stuName) throws SQLException;
// 查询单个用户信息
4️⃣ public Integer delOne(String stuName) throws SQLException;
// 删除单个用户信息
5️⃣ public Integer alterOne(Student student) throws SQLException;
//修改单个用户信息
6️⃣ public List<Student> selectAll(String acc) throws SQLException;
//模糊查询用户名
接口和dao层相同
public interface StudentService {
public Integer insertStudent(Student student) throws SQLException;
public List<Student> selectAll() throws SQLException;
public List<Student> selectAll(String acc) throws SQLException;
public Student selectOne(String stuName) throws SQLException;
public Integer delOne(String stuName) throws SQLException;
public Integer alterOne(Student student) throws SQLException;
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!-- 默认页面-->
<welcome-file-list>
<welcome-file>bootstrap_register.jsp</welcome-file>
</welcome-file-list>
<!-- session失效时间30分钟-->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>