目录
引言
项目需求
代码整体结构
? ? ? ? web
? ? ? ? ?Servlet
? ? ? ? Dao
? ? ? ? domin
? ? ? ? service
? ? ? ? utils
功能
? ? ? ? 登录功能
? ? ? ? ? ? ? ? User类
? ? ? ? ? ? ? ? UserDaoImp中的方法
? ? ? ? ? ? ? ? UserServiceImp中的方法
? ? ? ? ? ? ? ? CheckCodeServlet(验证码的Servlet类)
? ? ? ? ? ? ? ? LoginServlet(登录使用的Servlet类)
? ? ? ? ? ? ? ? login.jsp(登录界面展示)
? ? ? ? ? ? ? ? 登录功能效果展示:
? ? ? ? 添加功能
? ? ? ? ? ? ? ? User类(上述提过)
? ? ? ? ? ? ? ? UserDaoImp中的方法
? ? ? ? ? ? ? ? UsereServiceImp中的方法
? ? ? ? ? ? ? ? InsertUserServlet类
? ? ? ? ? ? ? ? add.jsp(添加客户界面展示)
? ? ? ? ? ? ? ? 功能展示
? ? ? ? ?修改功能
? ? ? ? ? ? ? ? User类(同上)
? ? ? ? ? ? ? ? UserDaoImp中的方法
? ? ? ? ? ? ? ? UserServiceImp中的方法
? ? ? ? ? ? ? ? FindAUserServlet
? ? ? ? ? ? ? ? UpdateServlet
? ? ? ? ? ? ? ? update.jsp(修改界面展示)
? ? ? ? ? ? ? ? 修改功能展示:
? ? ? ? ?删除功能
? ? ? ? ? ? ? ? User类(同上)
? ? ? ? ? ? ? ? UserDaoImp中的方法
? ? ? ? ? ? ? ? UserServiceImp中的方法
? ? ? ? ? ? ? ? DeleteUserServlet
? ? ? ? ? ? ? ? list.jsp(删除界面展示)
引言
? ? ? ? 学习完一部分前端知识和服务器知识后,这次的用户信息管理是前端+后端服务器+数据库的一次简单的项目实现,就只有简简单单的代码而已,不是完整的项目设计。
项目需求
? ? ? ? 用户先进行登录,进入系统后,在网页上展示用户数据,并且用户可直接在网页上进行增删改查操作,还包括删除选中项,分页展示,复杂查询这三个复杂功能。
代码整体结构
? ? ? ? web
? ? ? ? ?Servlet
? ? ? ? Dao
? ? ? ? domin
? ? ? ? service
? ? ? ? utils
?
? ? ? ? ? ? ? ? 工具类详细代码:
package utils;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;
/**
* @author 张天霸
*/
public class JDBCUtils {
private static DataSource source;
static {
try {
Properties pt = new Properties();
InputStream is = JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties");
pt.load(is);
source = DruidDataSourceFactory.createDataSource(pt);
} catch (Exception e) {
e.printStackTrace();
}
}
public static DataSource getSource(){
return source;
}
}
功能
? ? ? ? 登录功能
? ? ? ? ? ? ? ? User类
? ? ? ? ? ? ? ? 注意:由于只是一个简单的小练习,所以将用户名与密码也放进了uers类,正式项目中应该是再另外创建一个实体类,一个数据库
package domin;
/**
* @author 张天霸
*/
public class User {
private int id;
private String name;
private String gender;
private int age;
private String address;
private String qq;
private String email;
private String username;
private String password;
public User() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getQq() {
return qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", gender='" + gender + '\'' +
", age=" + age +
", address='" + address + '\'' +
", qq='" + qq + '\'' +
", email='" + email + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
? ? ? ? ? ? ? ? UserDaoImp中的方法
@Override
public User findUserByUsernameAndPassword(String username, String password) {
try {
String sql = "select * from user where username = ? and password = ?";
User user = template.queryForObject(sql, new BeanPropertyRowMapper<>(User.class), username, password);
return user;
} catch (DataAccessException e) {
e.printStackTrace();
return null;
}
}
? ? ? ? ? ? ? ? UserServiceImp中的方法
@Override
public User login(User user) {
return userDaoImp.findUserByUsernameAndPassword(user.getUsername(), user.getPassword());
}
? ? ? ? ? ? ? ? CheckCodeServlet(验证码的Servlet类)
package web.servlet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 验证码
*/
@WebServlet("/checkCodeServlet")
public class CheckCodeServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
//服务器通知浏览器不要缓存
response.setHeader("pragma","no-cache");
response.setHeader("cache-control","no-cache");
response.setHeader("expires","0");
//在内存中创建一个长80,宽30的图片,默认黑色背景
//参数一:长
//参数二:宽
//参数三:颜色
int width = 80;
int height = 30;
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
//获取画笔
Graphics g = image.getGraphics();
//设置画笔颜色为灰色
g.setColor(Color.GRAY);
//填充图片
g.fillRect(0,0, width,height);
//产生4个随机验证码,12Ey
String checkCode = getCheckCode();
//将验证码放入HttpSession中
request.getSession().setAttribute("CHECKCODE_SERVER",checkCode);
//设置画笔颜色为黄色
g.setColor(Color.YELLOW);
//设置字体的小大
g.setFont(new Font("黑体",Font.BOLD,24));
//向图片上写入验证码
g.drawString(checkCode,15,25);
//将内存中的图片输出到浏览器
//参数一:图片对象
//参数二:图片的格式,如PNG,JPG,GIF
//参数三:图片输出到哪里去
ImageIO.write(image,"PNG",response.getOutputStream());
}
/**
* 产生4位随机字符串
*/
private String getCheckCode() {
String base = "0123456789ABCDEFGabcdefg";
int size = base.length();
Random r = new Random();
StringBuffer sb = new StringBuffer();
for(int i=1;i<=4;i++){
//产生0到size-1的随机值
int index = r.nextInt(size);
//在base字符串中获取下标为index的字符
char c = base.charAt(index);
//将c放入到StringBuffer中去
sb.append(c);
}
return sb.toString();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request,response);
}
}
? ? ? ? ? ? ? ? LoginServlet(登录使用的Servlet类)
package web.servlet;
import domin.User;
import org.apache.commons.beanutils.BeanUtils;
import service.UserServiceImp;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
/**
* @author 张天霸
*/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String verifycode = request.getParameter("verifycode");
String checkcode_server = (String)request.getSession().getAttribute("CHECKCODE_SERVER");
request.getSession().removeAttribute("CHECKCODE_SERVER");
if (!checkcode_server.equals(verifycode)){
request.setAttribute("login_msg","验证码错误");
request.getRequestDispatcher("/login.jsp").forward(request,response);
return;
}
Map<String, String[]> map = request.getParameterMap();
User user = new User();
try {
BeanUtils.populate(user,map);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
UserServiceImp userServiceImp = new UserServiceImp();
User loginuser = userServiceImp.login(user);
if (loginuser != null){
request.getSession().setAttribute("user",loginuser);
response.sendRedirect(request.getContextPath()+"/index.jsp");
}else {
request.setAttribute("login_msg","用户名或密码错误");
request.getRequestDispatcher("/login.jsp").forward(request,response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
? ? ? ? ? ? ? ? login.jsp(登录界面展示)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>管理员登录</title>
<!-- 1. 导入CSS的全局样式 -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- 2. jQuery导入,建议使用1.9以上的版本 -->
<script src="js/jquery-2.1.0.min.js"></script>
<!-- 3. 导入bootstrap的js文件 -->
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function refreshCode() {
let vcode = document.getElementById("vcode");
vcode.src = "${pageContext.request.contextPath}/checkCodeServlet?time"+new Date().getTime();
}
</script>
</head>
<body>
<div class="container" style="width: 400px;">
<h3 style="text-align: center;">管理员登录</h3>
<form action="${pageContext.request.contextPath}/LoginServlet" method="post">
<div class="form-group">
<label for="user">用户名:</label>
<input type="text" name="username" class="form-control" id="user" placeholder="请输入用户名"/>
</div>
<div class="form-group">
<label for="password">密码:</label>
<input type="password" name="password" class="form-control" id="password" placeholder="请输入密码"/>
</div>
<div class="form-inline">
<label for="vcode">验证码:</label>
<input type="text" name="verifycode" class="form-control" id="verifycode" placeholder="请输入验证码" style="width: 120px;"/>
<a href="javascript:refreshCode()"><img src="${pageContext.request.contextPath}/checkCodeServlet" title="看不清点击刷新" id="vcode"/></a>
</div>
<hr/>
<div class="form-group" style="text-align: center;">
<input class="btn btn btn-primary" type="submit" value="登录">
</div>
</form>
<!-- 出错显示的信息框 -->
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" >
<span>×</span></button>
<strong>${login_msg}</strong>
</div>
</div>
</body>
</html>
? ? ? ? ? ? ? ? 登录功能效果展示:
? ? ? ? 添加功能
? ? ? ? ? ? ? ? User类(上述提过)
? ? ? ? ? ? ? ? UserDaoImp中的方法
@Override
public void insert(User user) {
String sql = "insert into user(name,gender,age,address,qq,email) VALUES(?,?,?,?,?,?)";
template.update(sql,user.getName(),user.getGender(),user.getAge(),
user.getAddress(),user.getQq(),user.getEmail());
}
? ? ? ? ? ? ? ? UsereServiceImp中的方法
@Override
public void insert(User user) {
userDaoImp.insert(user);
}
? ? ? ? ? ? ? ? InsertUserServlet类
package web.servlet;
import domin.User;
import org.apache.commons.beanutils.BeanUtils;
import service.UserServiceImp;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
/**
* @author 张天霸
*/
@WebServlet("/InsertUserServlet")
public class InsertUserServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
Map<String, String[]> map = request.getParameterMap();
User user = new User();
try {
BeanUtils.populate(user, map);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
UserServiceImp userServiceImp = new UserServiceImp();
userServiceImp.insert(user);
response.sendRedirect(request.getContextPath()+"/FindUserByPageServlet");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
? ? ? ? ? ? ? ? add.jsp(添加客户界面展示)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- HTML5文档-->
<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
<!-- 指定字符集 -->
<meta charset="utf-8">
<!-- 使用Edge最新的浏览器的渲染方式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- viewport视口:网页可以根据设置的宽度自动进行适配,在浏览器的内部虚拟一个容器,容器的宽度与设备的宽度相同。
width: 默认宽度与设备的宽度相同
initial-scale: 初始的缩放比,为1:1 -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>添加用户</title>
<!-- 1. 导入CSS的全局样式 -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- 2. jQuery导入,建议使用1.9以上的版本 -->
<script src="js/jquery-2.1.0.min.js"></script>
<!-- 3. 导入bootstrap的js文件 -->
<script src="js/bootstrap.min.js"></script>
<style>
.error {
color: red;
}
</style>
</head>
<body>
<div class="container">
<center><h3>添加联系人页面</h3></center>
<form action="${pageContext.request.contextPath}/InsertUserServlet" method="post" id="form">
<div class="form-group">
<label for="name">姓名:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="请输入姓名">
<span class="error" id="s_name"></span>
</div>
<div class="form-group">
<label>性别:</label>
<input type="radio" name="gender" value="男" checked="checked"/>男
<input type="radio" name="gender" value="女"/>女
</div>
<div class="form-group">
<label for="age">年龄:</label>
<input type="text" class="form-control" id="age" name="age" placeholder="请输入年龄">
<span class="error" id="s_age">
</span>
</div>
<div class="form-group">
<label for="address">籍贯:</label>
<select name="address" class="form-control" id="jiguan">
<option value="广东">广东</option>
<option value="广西">广西</option>
<option value="湖南">湖南</option>
</select>
</div>
<div class="form-group">
<label for="qq">QQ:</label>
<input type="text" class="form-control" id="qq" name="qq" placeholder="请输入QQ号码"/>
<span class="error" id="s_qq">
</span>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" name="email" placeholder="请输入邮箱地址"/>
</div>
<div class="form-group" style="text-align: center">
<input class="btn btn-primary" type="submit" value="提交"/>
<input class="btn btn-default" type="reset" value="重置"/>
<input class="btn btn-default" type="button" value="返回"/>
</div>
</form>
</div>
</body>
<script>
document.getElementById("form").onsubmit = function () {
return checkAge() && checkQQ() && checkName();
}
document.getElementById("age").onblur = checkAge;
document.getElementById("qq").onblur = checkQQ; //多了个()
document.getElementById("name").onblur = checkName;
function checkName() {
let name = document.getElementById("name").value;
let flag;
if (name === "") {
s_name.innerHTML = "不能为空!";
flag = false;
}else {
s_name.innerHTML = "";
flag = true
}
}
function checkAge() {
let age = document.getElementById("age").value;
let reg_age = /^\d{1,2}$/;
let flag = reg_age.test(age);
let s_age = document.getElementById("s_age");
if (flag) {
s_age.innerHTML = ""
} else {
s_age.innerHTML = "年龄输入错误!";
}
return flag;
}
function checkQQ() {
let qq = document.getElementById("qq").value;
let reg_qq = /^\d{4,12}$/;
let flag = reg_qq.test(qq);
let s_qq = document.getElementById("s_qq");
if (flag) {
s_qq.innerHTML = ""
} else {
s_qq.innerHTML = "qq输入错误!";
}
return flag;
}
</script>
</html>
? ? ? ? ? ? ? ? 功能展示
? ? ? ? ?修改功能
? ? ? ? ? ? ? ? User类(同上)
? ? ? ? ? ? ? ? UserDaoImp中的方法
@Override
public void update(User user) {
String sql = "update user set name = ?,gender = ?,age = ?, address = ?, qq = ? ,email = ? where id = ?";
template.update(sql, user.getName(), user.getGender(), user.getAge(), user.getAddress(), user.getQq(), user.getEmail(), user.getId());
}
@Override
public User findById(int id) {
String sql = "select * from user where id = ?";
User user = template.queryForObject(sql, new BeanPropertyRowMapper<>(User.class), id);
return user;
}
? ? ? ? ? ? ? ? UserServiceImp中的方法
@Override
public void update(User user) {
userDaoImp.update(user);
}
@Override
public User findById(String id) {
return userDaoImp.findById(Integer.parseInt(id));
}
? ? ? ? ? ? ? ? FindAUserServlet
? ? ? ? ? ? ? ? ? ? ? ? ·为了在修改界面默认展示出未修改的信息,所以需要先找到这个User对象
package web.servlet;
import domin.User;
import service.UserServiceImp;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @author 张天霸
*/
@WebServlet("/FindAUserServlet")
public class FindAUserServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
UserServiceImp userServiceImp = new UserServiceImp();
String id = request.getParameter("id");
User user = userServiceImp.findById(id);
request.setAttribute("user",user);
System.out.println(user);
request.getRequestDispatcher("/update.jsp").forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
? ? ? ? ? ? ? ? UpdateServlet
package web.servlet;
import domin.User;
import org.apache.commons.beanutils.BeanUtils;
import service.UserServiceImp;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
/**
* @author 张天霸
*/
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
Map<String, String[]> map = request.getParameterMap();
User user = new User();
try {
BeanUtils.populate(user,map);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
UserServiceImp userServiceImp = new UserServiceImp();
userServiceImp.update(user);
response.sendRedirect(request.getContextPath()+"/FindUserByPageServlet");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
? ? ? ? ? ? ? ? update.jsp(修改界面展示)
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
<!-- 指定字符集 -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>修改用户</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-2.1.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="width: 400px;">
<h3 style="text-align: center;">修改联系人</h3>
<form action="${pageContext.request.contextPath}/UpdateServlet" method="post">
<input type="hidden" name="id" value="${user.id}">
<div class="form-group">
<label for="name">姓名:</label>
<input type="text" class="form-control" id="name" name="name" value="${user.name}" readonly="readonly" placeholder="请输入姓名" />
</div>
<div class="form-group">
<label>性别:</label>
<c:if test="${user.gender == '男'}">
<input type="radio" name="gender" value="男" checked/>男
<input type="radio" name="gender" value="女" />女
</c:if>
<c:if test="${user.gender == '女'}">
<input type="radio" name="gender" value="男" />男
<input type="radio" name="gender" value="女" checked />女
</c:if>
</div>
<div class="form-group">
<label for="age">年龄:</label>
<input type="text" class="form-control" id="age" name="age" value="${user.age}" placeholder="请输入年龄" />
</div>
<div class="form-group">
<label for="address">籍贯:</label>
<select name="address" class="form-control" >
<c:if test="${user.address == '广东'}">
<option value="广东" selected>广东</option>
<option value="广西">广西</option>
<option value="湖南">湖南</option>
</c:if>
<c:if test="${user.address == '广西'}">
<option value="广东">广东</option>
<option value="广西" selected>广西</option>
<option value="湖南">湖南</option>
</c:if>
<c:if test="${user.address == '湖南'}">
<option value="广东">湖南</option>
<option value="广西">广西</option>
<option value="湖南" selected>湖南</option>
</c:if>
</select>
</div>
<div class="form-group">
<label for="qq">QQ:</label>
<input type="text" class="form-control" name="qq" value="${user.qq}" placeholder="请输入QQ号码"/>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" name="email" value="${user.email}" placeholder="请输入邮箱地址"/>
</div>
<div class="form-group" style="text-align: center">
<input class="btn btn-primary" type="submit" value="提交" />
<input class="btn btn-default" type="reset" value="重置" />
<input class="btn btn-default" type="button" value="返回"/>
</div>
</form>
</div>
</body>
</html>
? ? ? ? ? ? ? ? 修改功能展示:
? ? ? ? ?删除功能
? ? ? ? ? ? ? ? User类(同上)
? ? ? ? ? ? ? ? UserDaoImp中的方法
@Override
public void delete(String id) {
String sql = "delete from user where id = ?";
template.update(sql,id);
}
? ? ? ? ? ? ? ? UserServiceImp中的方法
@Override
public void delete(String id) {
userDaoImp.delete(id);
}
? ? ? ? ? ? ? ? DeleteUserServlet
package web.servlet;
import service.UserServiceImp;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author 张天霸
*/
@WebServlet("/DeleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
UserServiceImp serviceImp = new UserServiceImp();
serviceImp.delete(id);
response.sendRedirect(request.getContextPath()+"/FindUserByPageServlet");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
? ? ? ? ? ? ? ? list.jsp(删除界面展示)
? ? ? ? ? ? ? ? ? ? ? ? ·删除界面与分页展示以及删除选中功能展示在同一个jsp文件,所以这个文件代码展示在项目的另一个博客
用户信息管理项目练习——分页展示,复杂查询,删除选中条目功能_zhangtianba222的博客-CSDN博客
|