——————————DescriptionStart——————————
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明








基于javaweb的JSP+Servlet网上名片通讯录管理系统(java+servlet+jsp+bootstrap+mysql)
管理员:
admin 123456
用户:
user1 123456
user2 123456
*不同用户只能对自己名片进行操作
Java web 期末课程设计–名片管理系统
- Jsp+Servlet+JavaBean+Jdbc+DAO+MySQL+Bootstrap+jQuey。
- 其中也有一些不是很好的操作,譬如页面嵌套了iframe,其实应有更好的解决方案。
- 其中也牵扯对于ajax、EL表达式、JSTL、JSON等的应用
- 主要实现功能:
用户注册登录(注册时根据用户名检查用户是否存在)
不同用户只能对自己名片进行操作
名片增删(放入回收站)改查
批量勾选删除
四个字段的模糊查询(后端拼这个sql觉得真tm zz啊)
回收站管理(彻底删除名片、恢复删除名片)
用户权限管理(admin用户最起码得能管理其他普通用户吧) admin可实现对普通用户帐号的密码重置与删除,
普通用户可自主更改密码
(由于本人太懒,所以只实现了密码重置与删除用户)
未登录用户控制(登录都没登录,总不能直接访问到页面吧)
密码md5加密(密码不能明文存储吧)
登录图片验证码(可点击图片刷新)
- 待实现功能:
RememberMe
分页查询(是在懒得改了)
——————————CodeStart——————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Card card = new Card(id,name,tel,address,email,userId,isDelete); CardDao cardDao = new CardDao(); int n = cardDao.update(card); if (n > 0) { request.setAttribute("message","更新成功"); request.getRequestDispatcher("list").forward(request,response); } else { request.setAttribute("message","更新失败"); request.getRequestDispatcher("list").forward(request,response); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }
public class DeleteServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8");
String ids = request.getParameter("id"); CardDao cardDao = new CardDao(); Card card = new Card(); int n = 0; if (ids.contains("-")) { String[] id = ids.split("-"); for (String s : id) { card.setId(Integer.parseInt(s)); n += cardDao.remove(card); } } else { card.setId(Integer.parseInt(ids)); n = cardDao.remove(card); } response.setCharacterEncoding("utf-8"); if (n > 0) {
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }
public class AddServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); HttpSession session = request.getSession(); String name = request.getParameter("name"); String tel = request.getParameter("tel"); String address =request.getParameter("address"); String email = request.getParameter("email"); int userId = (int) session.getAttribute("userId"); Card card = new Card(0,name,tel,address,email,userId,0); CardDao cardDao = new CardDao(); int n = cardDao.create(card); if (n > 0) { request.getRequestDispatcher("list").forward(request,response); } else { request.setAttribute("message","名片插入失败!"); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
public class AddServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); HttpSession session = request.getSession(); String name = request.getParameter("name"); String tel = request.getParameter("tel"); String address =request.getParameter("address"); String email = request.getParameter("email"); int userId = (int) session.getAttribute("userId"); Card card = new Card(0,name,tel,address,email,userId,0); CardDao cardDao = new CardDao(); int n = cardDao.create(card); if (n > 0) { request.getRequestDispatcher("list").forward(request,response); } else { request.setAttribute("message","名片插入失败!"); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }
public class SelectServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String name = request.getParameter("name"); String tel = request.getParameter("tel"); String address = request.getParameter("address"); String email = request.getParameter("email"); Card card = new Card(0,name,tel,address,email,0,0); CardDao cardDao = new CardDao();
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| public int remove(Card card) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; int row = 0; try { conn = DBConnection.getConnection(); pstmt = conn.prepareStatement(REMOVE_SQL); pstmt.setInt(1,card.getId()); row = pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DBConnection.closeDB(conn,pstmt,rs); } return row; }
@Override public Card find(Card card) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; Card card1 = null; try { int id = card.getId(); conn = DBConnection.getConnection(); pstmt = conn.prepareStatement(SELECT_SQL); pstmt.setInt(1, id); rs = pstmt.executeQuery(); while (rs.next()) { String name = rs.getString("name"); String tel = rs.getString("tel"); String address = rs.getString("address"); String email = rs.getString("email"); int userId = rs.getInt("user_id"); int isDelete = rs.getInt("isdelete"); card1 = new Card(id, name, tel, address, email, userId, isDelete); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConnection.closeDB(conn, pstmt, rs); } return card1; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| conn = DBConnection.getConnection(); pstmt = conn.prepareStatement(DELETE_SQL); pstmt.setInt(1,user.getId()); row = pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DBConnection.closeDB(conn,pstmt,rs); } return row; }
@Override public int reset(User user) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; String RESET_SQL = "update tb_user set password='123456' where id = ?"; int row = 0; try { conn = DBConnection.getConnection(); pstmt = conn.prepareStatement(RESET_SQL); pstmt.setInt(1,user.getId()); row = pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DBConnection.closeDB(conn,pstmt,rs); } return row; }
@Override
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=401123422409201fv
https://javayms.pages.dev?id=401123422409201fv