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







基于javaweb的JSP+Servlet失物招领系统(java+jsp+servlet+c3p0+mysql)
项目介绍
本项目分为管理员、学生两种角色 学生可以查看失物、招领发布、信息浏览等; 管理员可以删除信息
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
- 后端:Servlet+c3p0 2. 前端:JSP
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中c3p0-config.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目,前台地址:http://localhost:8080/index.jsp 后台地址:http://localhost:8080/login.jsp 管理员账号/密码:admin/admin
——————————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 43 44 45 46 47 48 49 50
| xiaoxi.setWupin(wupin); xiaoxi.setLianxiren(lianxiren); xiaoxi.setTel(tel); xiaoxi.setImagesName(fileName);
XiaoxiDao xiaoxiDao = new XiaoxiDao(); int b=xiaoxiDao.insertsearch(xiaoxi); if(b==1) { request.getRequestDispatcher("/index.jsp").forward(request, response); } } protected void add_Findxiaoxi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String zhuti = request.getParameter("zhuti"); String neirong = request.getParameter("neirong"); String wupin = request.getParameter("wupin"); String lianxiren = request.getParameter("lianxiren"); String tel = request.getParameter("tel");
String imagePath =request.getParameter(""); Part part = request.getPart("pic"); System.out.println("______________>"+part); String fileName = photoDao.getPhotoNewName(); String savePath = request.getSession().getServletContext().getRealPath("/imgs");
System.out.println("保存路径:"+savePath); File f = new File(savePath+"/"); if(!f.exists()) { f.mkdirs(); } part.write(savePath+"/"+fileName);
String t = request.getSession().getServletContext().getRealPath("sensitiveWords.txt"); SensitiveWordFilter filter = new SensitiveWordFilter(t); System.out.println("敏感词的数量:" + filter.sensitiveWordMap.size()); Set<String> set = filter.getSensitiveWord(neirong, 1); System.out.println("语句中包含敏感词的个数为:" + set.size() + "。包含:" + set); System.out.println("替换关敏感词"); String newNeirong = filter.replaceSensitiveWord(neirong,2,"*"); System.out.println(newNeirong);
|
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
| request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("GB2312"); String methodName = request.getParameter("method");
try { Method method = getClass().getDeclaredMethod(methodName, HttpServletRequest.class, HttpServletResponse.class); method.setAccessible(true); method.invoke(this, request, response); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
protected void add_Searchxiaoxi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); String zhuti = request.getParameter("zhuti"); String neirong = request.getParameter("neirong"); String wupin = request.getParameter("wupin"); String lianxiren = request.getParameter("lianxiren"); String tel = request.getParameter("tel");
Part part = request.getPart("pic"); String fileName = photoDao.getPhotoNewName(); String savePath = request.getSession().getServletContext().getRealPath("/imgs");
System.out.println("保存路径:"+savePath); File f = new File(savePath+"/"); if(!f.exists()) { f.mkdirs(); } part.write(savePath+"/"+fileName); Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String dateNow = sdf.format(d);
|
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
| } if(psw!=null&&!psw.equals(mima)){ request.getRequestDispatcher("/login.jsp").forward(request, response); } if(psw.equals(mima)){ request.getRequestDispatcher("/admin.jsp").forward(request, response); } } protected void finf_UserXiaoxi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("GB2312"); String id1 = request.getParameter("id"); int user_id = Integer.getInteger(id1); XiaoxiDao xiaoxiDao = new XiaoxiDao(); Xiaoxi xiaoxi=xiaoxiDao.findByUser(user_id); request.setAttribute("xiaoxi", xiaoxi); request.getRequestDispatcher("/edit-employee.jsp").forward(request, response); } } package dao;
public class photoDao {
public static List<FileItem> getRequsetFileItems(HttpServletRequest request,ServletContext servletContext){ boolean isMultipart=ServletFileUpload.isMultipartContent(request); if(isMultipart) { DiskFileItemFactory factory = new DiskFileItemFactory(); String str="javax.servelet.context.tempdir"; File repository=(File) servletContext.getAttribute(str); factory.setRepository(repository); ServletFileUpload upload=new ServletFileUpload(factory); try { System.out.println("获取到了文件"); return upload.parseRequest(request);
|
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
|
@WebServlet("/xiaoxiServlet") @MultipartConfig public class XiaoxiServlet extends HttpServlet { private static final long serialVersionUID = 1L;
public XiaoxiServlet() { super(); }
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 43 44 45 46 47 48 49 50 51
| boolean isMultipart=ServletFileUpload.isMultipartContent(request); if(isMultipart) { DiskFileItemFactory factory = new DiskFileItemFactory(); String str="javax.servelet.context.tempdir"; File repository=(File) servletContext.getAttribute(str); factory.setRepository(repository); ServletFileUpload upload=new ServletFileUpload(factory); try { System.out.println("获取到了文件"); return upload.parseRequest(request); }catch (FileUploadException e) { System.out.println("没有获取到文件"); return null; } }else { System.out.println("没有获取到文件"); return null; } }
public static boolean saveFile(FileItem item,String fileName) { File savePath=new File("D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\imgs"); if(!savePath.exists()) { savePath.mkdirs(); } File uploadFile=new File(savePath+File.separator+fileName); try{ item.write(uploadFile); System.out.println("保存文件成功"); return true; }catch(Exception e){ System.out.println("保存文件失败"); } return false; }
public static int getSecondTimestamp(Date date){ if (null == date) { return 0; } String timestamp = String.valueOf(date.getTime()); System.out.println(timestamp); int length = timestamp.length(); if (length > 3) { return Integer.valueOf(timestamp.substring(0,length-3));
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=321122522008200or
https://javayms.pages.dev?id=321122522008200or