简易的CRM系统案例之Servlet+Jsp+MySQL版本
数据库配置
datebase.properties
driver=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/infos username=root password=root
/* Navicat MySQL Data Transfer Source Server : loaderman Source Server Version : 50540 Source Host : localhost:3306 Source Database : infos Target Server Type : MYSQL Target Server Version : 50540 File Encoding : 65001 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for t_account -- ---------------------------- DROP TABLE IF EXISTS `t_account`; CREATE TABLE `t_account` ( `id` int(4) NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL, `password` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -- ---------------------------- -- Table structure for t_policy -- ---------------------------- DROP TABLE IF EXISTS `t_policy`; CREATE TABLE `t_policy` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `tel` varchar(100) NOT NULL, `policyID` varchar(100) NOT NULL, `policyName` varchar(100) NOT NULL, `orderTime` varchar(100) NOT NULL, `orderType` varchar(100) NOT NULL, `policyMoney` varchar(100) NOT NULL, `profitPercentage` varchar(100) DEFAULT NULL, `insuranceCoverage` varchar(255) DEFAULT NULL, `orderPayYears` varchar(255) DEFAULT NULL, `safeguardYear` varchar(255) DEFAULT NULL, `profitMoney` varchar(100) DEFAULT NULL, `remark` longtext, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; -- ---------------------------- -- Table structure for t_user -- ---------------------------- DROP TABLE IF EXISTS `t_user`; CREATE TABLE `t_user` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL , `sex` varchar(100) DEFAULT NULL , `age` varchar(255) DEFAULT NULL, `telephone` varchar(100) NOT NULL , `grade` varchar(255) DEFAULT NULL, `idCard` varchar(100) DEFAULT NULL , `address` varchar(200) DEFAULT NULL , `weixin` varchar(100) DEFAULT NULL , `qq` varchar(100) DEFAULT NULL , `email` varchar(100) DEFAULT NULL , `area` varchar(255) DEFAULT NULL, `job` varchar(100) DEFAULT NULL , `remark` longtext COMMENT '备注', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8;
package com.loaderman.crm.util; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /* * @ class description:工具类,用来加载properties文件 * */ public class ConfigManager { private Properties properties; private static ConfigManager configManager; public ConfigManager(){ String filePath="database.properties"; InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream(filePath); properties = new Properties(); try { properties.load(is); is.close(); } catch (IOException e) { e.printStackTrace(); } } //创建唯一一个实例对象使用了单例模式 public static synchronized ConfigManager getInstance(){ if(configManager == null){ configManager = new ConfigManager(); } return configManager; } public String getString(String key){ return properties.getProperty(key); } }
package com.loaderman.crm.dao; import com.loaderman.crm.util.ConfigManager; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /* * @ class description:数据库操作的基类,连接、查询、释放资源 */ public class BaseDao { Connection connection = null; PreparedStatement pstm = null; ResultSet rs = null; //获取数据库连接 public boolean getConnection(){ try { Class.forName(ConfigManager.getInstance().getString("driver")); String url = ConfigManager.getInstance().getString("url"); String username = ConfigManager.getInstance().getString("username"); String password = ConfigManager.getInstance().getString("password"); connection = DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); return false; } catch (SQLException e) { e.printStackTrace(); return false; } return true; } //对数据库的增加、删除、修改,返回SQL语句影响的行数 public int executeUpdateSQL(String sql,Object[] params){ int row = 0; if(getConnection()){ try { pstm = connection.prepareStatement(sql); for(int i = 0; i < params.length; i++){ pstm.setObject(i+1, params[i]); } row = pstm.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } } return row; } //对数据库的查询,返回查询结果集合 public ResultSet executeQuerySQL(String sql, Object[] params){ if(getConnection()){ try { pstm = connection.prepareStatement(sql); for(int i = 0; i < params.length; i++){ pstm.setObject(i+1, params[i]); } rs = pstm.executeQuery(); } catch (SQLException e) { e.printStackTrace(); } } return rs; } //关闭资源 public void closeAllResource(){ if(connection != null){ try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } if(pstm != null){ try { pstm.close(); } catch (SQLException e) { e.printStackTrace(); } } if(rs != null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
添加数据库连接Jar包到项目中
DAO层
package com.loaderman.crm.dao; import com.loaderman.crm.entity.User; import java.util.List; /* * * @ class description:对客户表的操作接口 * */ public interface UserDao { //获取所有客户信息 public List<User> getAllUser(); //获取指定客户信息 public User getUserMoreInfo(User user); public List<User> getUserByName(String name); //添加客户 public int addUser(User user); //删除客户 public int delUser(User user); //修改客户 public int modifyUser(User user); //查找指定的客户存在不存在 public boolean findUser(User user); }
package com.loaderman.crm.dao.impl; import com.loaderman.crm.dao.BaseDao; import com.loaderman.crm.dao.UserDao; import com.loaderman.crm.entity.User; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class UserDaoimp extends BaseDao implements UserDao { @Override //获取所有客户信息 public List<User> getAllUser() { List<User> list = new ArrayList<User>(); String sql = "select * from t_user"; Object[] params = {}; ResultSet rs = this.executeQuerySQL(sql, params); try { while (rs.next()) { User user = new User(); user.setId(rs.getInt("id")); user.setName(rs.getString("name")); user.setSex(rs.getString("sex")); user.setTelephone(rs.getString("telephone")); user.setAge(rs.getString("age")); user.setGrade(rs.getString("grade")); user.setIdCard(rs.getString("idCard")); user.setWeixin(rs.getString("weixin")); user.setQq(rs.getString("qq")); user.setAddress(rs.getString("address")); user.setEmail(rs.getString("email")); user.setJob(rs.getString("job")); user.setArea(rs.getString("area")); user.setRemark(rs.getString("remark")); list.add(user); } } catch (SQLException e) { e.printStackTrace(); } return list; } @Override public User getUserMoreInfo(User user) { User user1 = new User(); String sql = "select * from t_user where `id`=?"; Object[] params = { user.getId() }; ResultSet rs = this.executeQuerySQL(sql, params); try { while (rs.next()) { user1.setId(rs.getInt("id")); user1.setName(rs.getString("name")); user1.setSex(rs.getString("sex")); user1.setTelephone(rs.getString("telephone")); user1.setAge(rs.getString("age")); user1.setGrade(rs.getString("grade")); user1.setIdCard(rs.getString("idCard")); user1.setWeixin(rs.getString("weixin")); user1.setQq(rs.getString("qq")); user1.setArea(rs.getString("area")); user1.setAddress(rs.getString("address")); user1.setEmail(rs.getString("email")); user1.setJob(rs.getString("job")); user1.setRemark(rs.getString("remark")); } } catch (SQLException e) { e.printStackTrace(); } return user1; } @Override public List<User> getUserByName(String name) { List<User> list = new ArrayList<User>(); String sql = "select * from t_user where `name`=?"; Object[] params = { name}; ResultSet rs = this.executeQuerySQL(sql, params); try { while (rs.next()) { User user = new User(); user.setId(rs.getInt("id")); user.setName(rs.getString("name")); user.setSex(rs.getString("sex")); user.setTelephone(rs.getString("telephone")); user.setAge(rs.getString("age")); user.setGrade(rs.getString("grade")); user.setIdCard(rs.getString("idCard")); user.setWeixin(rs.getString("weixin")); user.setQq(rs.getString("qq")); user.setArea(rs.getString("area")); user.setAddress(rs.getString("address")); user.setEmail(rs.getString("email")); user.setJob(rs.getString("job")); user.setRemark(rs.getString("remark")); list.add(user); } } catch (SQLException e) { e.printStackTrace(); } return list; } @Override //添加学生 public int addUser(User user) { int row = 0; String sql = "insert into t_user(`id`,`name`,`age`,`sex`,`telephone`,`grade`,`idCard`,`address`," + "`weixin`,`qq`,`email`,`job`,`remark`,`area`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; Object[] params = {user.getId(), user.getName(), user.getAge(), user.getSex(), user.getTelephone(), user.getGrade(),user.getIdCard(), user.getAddress(),user.getWeixin(),user.getQq(),user.getEmail(), user.getJob(),user.getRemark(),user.getArea()}; row = this.executeUpdateSQL(sql, params); if(row>0){ System.out.println("增加成功"); }else{ System.out.println("增加失败"); } return row; } @Override //删除 public int delUser(User user) { int row = 0; String sql = "delete from t_user where `id`=?"; Object[] params = {user.getId()}; row = this.executeUpdateSQL(sql, params); if(row>0){ System.out.println("删除成功"); }else{ System.out.println("删除失败"); } return row; } @Override public int modifyUser(User user) { int row = 0; String sql = "update t_user set `name`=?,`sex`=?,`telephone`=?,`age`=?,`grade`=?," + "`idCard`=?,`address`=?,`weixin`=? ,`qq`=? ,`email`=? ,`job`=? ,`remark`=? where `id`=?"; Object[] params = { user.getName(), user.getSex(), user.getTelephone(), user.getAge(), user.getGrade(), user.getIdCard(),user.getAddress(), user.getWeixin(), user.getQq(), user.getEmail(), user.getJob(), user.getRemark(),user.getId()}; row = this.executeUpdateSQL(sql, params); if(row>0){ System.out.println("修改成功"); }else{ System.out.println("修改失败"); } return row; } //查找指定的客户存在不存在 public boolean findUser(User user){ boolean flag = true; int row = 0; String sql = "select count(1) from t_user where `name`=? and `telephone`=? "; Object[] params = {user.getName(), user.getTelephone()}; ResultSet rs = this.executeQuerySQL(sql, params); try { while(rs.next()){ row = rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } if(row>0){ System.out.println("此客户已经存在"); flag = true; }else{ System.out.println("没有这个客户"); flag = false; } return flag; } }
实体类:
package com.loaderman.crm.entity; /* * @ class description:客户实体类 * */ public class User { private int id; private String name; private String sex; private String age; private String telephone; private String idCard; private String address; private String weixin ; private String qq; private String email; private String job; private String grade; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public String getArea() { return area; } public void setArea(String area) { this.area = area; } private String remark; private String area; public User() { } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } public String getIdCard() { return idCard; } public void setIdCard(String idCard) { this.idCard = idCard; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getWeixin() { return weixin; } public void setWeixin(String weixin) { this.weixin = weixin; } 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; } public String getJob() { return job; } public void setJob(String job) { this.job = job; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } @Override public String toString() { return "User{" + "name='" + name + '\'' + ", sex='" + sex + '\'' + ", age='" + age + '\'' + ", telephone='" + telephone + '\'' + ", idCard='" + idCard + '\'' + ", address='" + address + '\'' + ", weixin='" + weixin + '\'' + ", qq='" + qq + '\'' + ", email='" + email + '\'' + ", job='" + job + '\'' + ", grade='" + grade + '\'' + ", remark='" + remark + '\'' + ", area='" + area + '\'' + '}'; } }
Service层:
package com.loaderman.crm.service; import com.loaderman.crm.entity.User; import java.util.List; /* * @ Copyright (c) Create by JASON Date:2018-02-10 All rights reserved. * * @ class description:操作客户 * */ public interface UserService { public List<User> getAllUser(); public User getUserMoreInfo(User user); public List<User> getUserByName(String name); public int addUser(User user); public int delUser(User user); public int modifyUser(User user); public boolean findUser(User user); }
package com.loaderman.crm.service.impl; import com.loaderman.crm.dao.UserDao; import com.loaderman.crm.dao.impl.UserDaoimp; import com.loaderman.crm.entity.User; import com.loaderman.crm.service.UserService; import java.util.List; /* * * @ class description:操作客户 * */ public class UserServiceimp implements UserService { private UserDao userDao = null; public UserServiceimp(){ userDao = new UserDaoimp(); } @Override public List<User> getAllUser() { return userDao.getAllUser(); } @Override public User getUserMoreInfo(User user) { return userDao.getUserMoreInfo(user); } @Override public List<User> getUserByName(String name) { return userDao.getUserByName(name); } @Override public int addUser(User user) { return userDao.addUser(user); } @Override public int delUser(User user) { return userDao.delUser(user); } @Override public int modifyUser(User user) { return userDao.modifyUser(user); } public boolean findUser(User user){ return userDao.findUser(user); } }
web层
package com.loaderman.crm.servlet; import com.loaderman.crm.entity.User; import com.loaderman.crm.service.UserService; import com.loaderman.crm.service.impl.UserServiceimp; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; public class getUserList extends HttpServlet { private static final long serialVersionUID = 5804433309240831094L; public getUserList() { super(); } public void destroy() { super.destroy(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); System.out.println("name"+name); if (name!=null&&(!name.isEmpty())){ name =new String(name.getBytes("ISO8859-1"), "UTF-8"); System.out.println("name"+name); UserService stuService = new UserServiceimp(); List<User> list = stuService.getUserByName(name); request.setAttribute("list", list); }else { UserService stuService = new UserServiceimp(); List<User> list = stuService.getAllUser(); request.setAttribute("list", list); } //跳转页面 request.getRequestDispatcher("/pages/userList.jsp").forward(request, response); } public void init() throws ServletException { } }
package com.loaderman.crm.servlet; import com.loaderman.crm.entity.User; import com.loaderman.crm.service.UserService; import com.loaderman.crm.service.impl.UserServiceimp; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class delUser extends HttpServlet { private static final long serialVersionUID = 8988759302676261138L; public delUser() { super(); } public void destroy() { super.destroy(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { UserService userService = new UserServiceimp(); System.out.println(request.getParameter("id")); int id = Integer.parseInt(request.getParameter("id")); User stu = new User(); stu.setId(id); userService.delUser(stu); response.sendRedirect("/servlet/getUserList"); } public void init() throws ServletException { } }
package com.loaderman.crm.servlet; import com.loaderman.crm.entity.User; import com.loaderman.crm.service.UserService; import com.loaderman.crm.service.impl.UserServiceimp; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class addUser extends HttpServlet { private static final long serialVersionUID = 5804433309240831094L; public addUser() { super(); } public void destroy() { super.destroy(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); String sex = request.getParameter("sex"); String age = request.getParameter("age"); String telephone = request.getParameter("telephone"); String idCard = request.getParameter("idCard"); String area = request.getParameter("area"); String weixin = request.getParameter("weixin"); String qq = request.getParameter("qq"); String job = request.getParameter("job"); String grade = request.getParameter("grade"); String remark = request.getParameter("remark"); String address = request.getParameter("address"); String email = request.getParameter("email"); User user = new User(); user.setName(name); user.setSex(sex); user.setAge(age); user.setAge(age); user.setTelephone(telephone); user.setIdCard(idCard); user.setWeixin(weixin); user.setQq(qq); user.setArea(area); user.setJob(job); user.setRemark(remark); user.setGrade(grade); user.setAddress(address); user.setEmail(email); UserService studentService = new UserServiceimp(); System.out.println(user.toString()); String opr = request.getParameter("opr");//根据传的opr参数决定是添加学生还是修改学生信息 int n = 0; if (opr.equals("addUser")) { n = studentService.addUser(user); } else if (opr.equals("modifyUser")) { int id = Integer.parseInt(request.getParameter("id")); user.setId(id); n = studentService.modifyUser(user); } if (n > 0) { response.sendRedirect("/servlet/getUserList"); } else { response.sendRedirect("/pages/addUser.jsp"); } } public void init() throws ServletException { } }
addUser,jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page isELIgnored="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加客户</title> <link href="${pageContext.request.contextPath }/css/common.css" rel="stylesheet" type="text/css"/> <script type="text/javascript"> function check() { for (var i = 0; i < document.form1.elements.length - 1; i++) { if (document.form1.elements[i].value == "") { alert("当前表单不能有空项"); document.form1.elements[i].focus(); return false; } } return true; } </script> </head> <body> <h2>添加客户基本信息</h2> <form action="${pageContext.request.contextPath }/servlet/addUser?opr=addUser" name="form1" method="post" onsubmit="return check()"> <table id="stuDetailList"> <tr> <td>姓名:</td> <td><input type="text" name="name"></td> </tr> <tr> <td>性别:</td> <td><input type="radio" name="sex" value="男" checked="checked">男<input type="radio" name="sex" value="女">女 </td> </tr> <tr> <td>年龄:</td> <td><input type="text" name="age"></td> </tr> <tr> <td>手机:</td> <td><input type="text" name="telephone"></td> </tr> <tr> <td>身份证:</td> <td><input type="text" name="idCard"></td> </tr> <tr> <td>地区</td> <td><select name="area"> <option value="西安地区" selected="selected">西安地区</option> <option value="省内其他地区">省内其他地区</option> <option value="省内其他地区">省内其他地区</option> </select> </td> </tr> <tr> <td>微信:</td> <td><input type="text" name="weixin"></td> </tr> <tr> <td>QQ:</td> <td><input type="text" name="qq"></td> </tr> <tr> <td>职业:</td> <td><input type="text" name="job"></td> </tr> <tr> <td>地址:</td> <td><input type="text" name="address"></td> </tr> <tr> <td>邮箱:</td> <td><input type="text" name="email"></td> </tr> <tr> <td>客户等级</td> <td><select name="grade"> <option value="钻石客户">钻石客户</option> <option value="铂金客户">铂金客户</option> <option value="黄金客户">黄金客户</option> <option value="白银客户">白银客户</option> <option value="黄铜客户">黄铜客户</option> <option value="普通客户" selected="selected">普通客户</option> </select> </td> </tr> <tr> <td>备注:</td> <td><textarea name="remark" cols="40" rows="6"></textarea></td> </tr> <tr> <td colspan="2" style="text-align: center"><input type="submit" value="提交信息"></td> </tr> </table> </form> </body> </html>
modifyUser.jsp
<%@page import="com.loaderman.crm.service.impl.UserServiceimp" %> <%@page import="com.loaderman.crm.service.UserService" %> <%@page import="com.loaderman.crm.entity.User" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page isELIgnored="false" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>修改客户信息</title> <link href="${pageContext.request.contextPath }/css/common.css" rel="stylesheet" type="text/css"/> </head> <body> <h2>修改客户信息</h2> <form action="${pageContext.request.contextPath }/servlet/addUser?opr=modifyUser" method="post"> <table id="stuDetailList"> <% int id = Integer.parseInt(request.getParameter("id")); UserService studentService = new UserServiceimp(); User user = new User(); user.setId(id); user = studentService.getUserMoreInfo(user); %> <tr> <td>姓名:</td> <td><input type="text" name="name" value="<%=user.getName() %>"></td> </tr> <tr> <td>性别:</td> <td><input type="radio" name="sex" value="男" checked="checked">男<input type="radio" name="sex" value="女">女 </td> </tr> <tr> <td>年龄:</td> <td><input type="text" name="age" value="<%=user.getAge() %>"></td> </tr> <tr> <td>手机:</td> <td><input type="text" name="telephone" value="<%=user.getTelephone() %>"></td> </tr> <tr> <td>身份证:</td> <td><input type="text" name="idCard" value="<%=user.getIdCard() %>"></td> </tr> <tr> <td>地区</td> <td><select name="area"> <option value="西安地区" selected="selected">西安地区</option> <option value="省内其他地区">省内其他地区</option> <option value="省外地区">省外地区</option> </select> </td> </tr> <tr> <td>微信:</td> <td><input type="text" name="weixin" value="<%=user.getWeixin() %>"></td> </tr> <tr> <td>QQ:</td> <td><input type="text" name="qq" value="<%=user.getQq() %>"></td> </tr> <tr> <td>职业:</td> <td><input type="text" name="job" value="<%=user.getJob() %>"></td> </tr> <tr> <td>地址:</td> <td><input type="text" name="job" value="<%=user.getAddress() %>"></td> </tr> <tr> <td>邮箱:</td> <td><input type="text" name="job" value="<%=user.getEmail() %>"></td> </tr> <tr> <td>客户等级</td> <td><select name="grade"> <option value="钻石客户">钻石客户</option> <option value="铂金客户">铂金客户</option> <option value="黄金客户">黄金客户</option> <option value="白银客户">白银客户</option> <option value="黄铜客户">黄铜客户</option> <option value="普通客户" selected="selected">普通客户</option> </select> </td> </tr> <tr> <td>备注:</td> <td><textarea name="remark" cols="40" rows="6"><%=user.getRemark() %></textarea></td> </tr> <tr> <td><input type="hidden" name="id" value="<%=id %>"></td> <td colspan="2" style="text-align: center"><input type="submit" value="提交信息"></td> </tr> </table> </form> </body> </html>
getUserList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page isELIgnored="false" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>客户信息列表</title> <link href="${pageContext.request.contextPath }/css/common.css" rel="stylesheet" type="text/css"/> <script type="text/javascript"> function check() { var mymessage = confirm("确定要删除吗?"); if (mymessage == true) { return true; } else if (mymessage == false) { return false; } } </script> </head> <body> <div align="right">欢迎你,${account.username } <a href="logout.jsp">退出</a></div> <h2>客户信息列表</h2> <div align="right" style="margin-right: 50px"> <form action="/servlet/getUserList" style="text-align: right" > <tr> <input type="text" placeholder="请输入要查询姓名" name="name"></td> </tr> <td ><input type="submit" value="查询"></td> </tr> </form> <p> <a href="/pages/addUser.jsp"><input type="button" value="添加客户"></a> <a href="/servlet/getPolicyList"><input type="button" value="保单列表"></a> </p> </div> <table> <tr> <td class="listTable">编号</td> <td class="listTable">姓名</td> <td class="listTable">性别</td> <td class="listTable">年龄</td> <td class="listTable">电话</td> <td class="listTable">等级</td> <td class="listTable">身份证</td> <td class="listTable">地区</td> <td class="listTable">地址</td> <td class="listTable">微信</td> <td class="listTable">QQ</td> <td class="listTable">邮箱</td> <td class="listTable">职业</td> <td id="profile">备注</td> <td id="operate">操作</td> </tr> <c:forEach items="${list}" var="user" varStatus="idx"> <tr> <td>${idx.count} </td> <td>${user.getName()} </td> <td>${user.getSex()} </td> <td>${user.getAge()} </td> <td>${user.getTelephone()} </td> <td>${user.getGrade()} </td> <td>${user.getIdCard()} </td> <td>${user.getArea()} </td> <td>${user.getAddress()} </td> <td>${user.getWeixin()} </td> <td>${user.getQq()} </td> <td>${user.getEmail()} </td> <td>${user.getJob()} </td> <td>${user.getRemark()} </td> <td><a href="/pages/userDetail.jsp?id=${user.getId()}">查看 </a> <a href="/pages/modifyUser.jsp?id=${user.getId()}">修改 </a> <a href="${pageContext.request.contextPath }/servlet/delUser?id=${user.getId()}" onclick="return check()">删除 </a></td> </tr> </c:forEach > </table> </body> </html>
web.xml配置
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <filter> <filter-name>charSet</filter-name> <filter-class>com.loaderman.crm.filter.CharEncodingFilter</filter-class> </filter> <filter> <filter-name>loginFilter</filter-name> <filter-class>com.loaderman.crm.filter.LoginFillter</filter-class> </filter> <filter-mapping> <filter-name>charSet</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>loginFilter</filter-name> <url-pattern>/pages/*</url-pattern> </filter-mapping> <servlet> <servlet-name>doLogin</servlet-name> <servlet-class>com.loaderman.crm.servlet.doLogin</servlet-class> </servlet> <servlet> <servlet-name>addUser</servlet-name> <servlet-class>com.loaderman.crm.servlet.addUser</servlet-class> </servlet> <servlet> <servlet-name>delUser</servlet-name> <servlet-class>com.loaderman.crm.servlet.delUser</servlet-class> </servlet> <servlet> <servlet-name>addPolicy</servlet-name> <servlet-class>com.loaderman.crm.servlet.addPolicy</servlet-class> </servlet> <servlet> <servlet-name>getUserList</servlet-name> <servlet-class>com.loaderman.crm.servlet.getUserList</servlet-class> </servlet> <servlet> <servlet-name>getPolicyList</servlet-name> <servlet-class>com.loaderman.crm.servlet.getPolicyList</servlet-class> </servlet> <servlet> <servlet-name>delPolicy</servlet-name> <servlet-class>com.loaderman.crm.servlet.delPolicy</servlet-class> </servlet> <servlet-mapping> <servlet-name>doLogin</servlet-name> <url-pattern>/servlet/doLogin</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>addUser</servlet-name> <url-pattern>/servlet/addUser</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>delUser</servlet-name> <url-pattern>/servlet/delUser</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>addPolicy</servlet-name> <url-pattern>/servlet/addPolicy</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>getUserList</servlet-name> <url-pattern>/servlet/getUserList</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>getPolicyList</servlet-name> <url-pattern>/servlet/getPolicyList</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>delPolicy</servlet-name> <url-pattern>/servlet/delPolicy</url-pattern> </servlet-mapping> <error-page> <error-code>404</error-code> <location>/notFoundError.jsp</location> </error-page> </web-app>
点击 源码下载
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!