基于javaweb+mysql的jsp+servlet失物招领系统(java+jsp+servlet+c3p0+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的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项目:否;
技术栈
使用说明
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
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");
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel);
Part part = request.getPart("pic");
String fileName = photoDao.getPhotoNewName();
String savePath = request.getSession().getServletContext().getRealPath("/imgs");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\imgs";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateNow = sdf.format(d);
Xiaoxi xiaoxi = new Xiaoxi();
xiaoxi.setZhuti(zhuti);
xiaoxi.setNeirong(newNeirong);
// xiaoxi.setNeirong(neirong);
xiaoxi.setShijian(dateNow);
xiaoxi.setWupin(wupin);
xiaoxi.setLianxiren(lianxiren);
xiaoxi.setTel(tel);
xiaoxi.setImagesName(fileName);
XiaoxiDao xiaoxiDao = new XiaoxiDao();
int b=xiaoxiDao.insertfind(xiaoxi);
if(b==1) {
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
}
//模糊查询
protected void findMohu_Xiaoxi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
String zhuti = request.getParameter("zhuti");
XiaoxiDao xiaoxiDao = new XiaoxiDao();
ArrayList<Xiaoxi> xiaoxi =null;
xiaoxi = xiaoxiDao.findmohuAll("%"+zhuti+"%");
System.out.println("%"+zhuti+"%");
if(xiaoxi==null){
request.setAttribute("msg", "没有该物品信息!");
request.getRequestDispatcher("/found.jsp").forward(request, response);
} else {
request.setAttribute("zhuti", zhuti);
request.setAttribute("xiaoxi", xiaoxi);
request.getRequestDispatcher("/found.jsp").forward(request, response);
//response.setHeader("Refresh","1;url=welcome.jsp");
}
}
// 删除寻物信息
protected void deleteById_xiaoxi1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
XiaoxiDao xiaoxiDao = new XiaoxiDao();
String id = request.getParameter("id");
int idInt = Integer.parseInt(id);
int b = xiaoxiDao.delete(idInt);
if(b==1) {
request.getRequestDispatcher("/search-manager.jsp").forward(request, response);
}
}
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public XiaoxiServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
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 {
xiaoxi.setNeirong(newNeirong);
xiaoxi.setShijian(dateNow);
xiaoxi.setWupin(wupin);
xiaoxi.setLianxiren(lianxiren);
xiaoxi.setTel(tel);
xiaoxi.setImagesName(fileName);
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel+" "+"\n"+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");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\imgs";
System.out.println("保存路径:"+savePath);
File f = new File(savePath+"/");
if(!f.exists()) {
f.mkdirs();
}
part.write(savePath+"/"+fileName);
// 处理敏感词问题
// String t = getServletContext().getRealPath("/sensitiveWords.txt");
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");
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel);
Part part = request.getPart("pic");
String fileName = photoDao.getPhotoNewName();
String savePath = request.getSession().getServletContext().getRealPath("/imgs");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\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);
// 处理敏感词问题
String t = request.getSession().getServletContext().getRealPath("sensitiveWords.txt");
// String t = getServletContext.getRealPath("/sensitiveWords.txt");
SensitiveWordFilter filter = new SensitiveWordFilter(t);
System.out.println("敏感词的数量:" + filter.sensitiveWordMap.size());
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");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\imgs";
System.out.println("保存路径:"+savePath);
File f = new File(savePath+"/");
if(!f.exists()) {
f.mkdirs();
}
part.write(savePath+"/"+fileName);
// 处理敏感词问题
// String t = getServletContext().getRealPath("/sensitiveWords.txt");
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);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateNow = sdf.format(d);
Xiaoxi xiaoxi = new Xiaoxi();
xiaoxi.setZhuti(zhuti);
xiaoxi.setNeirong(newNeirong);
// xiaoxi.setNeirong(neirong);
xiaoxi.setShijian(dateNow);
/**
* Servlet implementation class UserServlet
*/
@WebServlet("/guanliyuanServlet")
public class GuanliyuanServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuanliyuanServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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 login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
public class photoDao {
/*这个函数的功能是获取前端的数据集合,将文件打包成File以便后续操作
*/
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);
}catch (FileUploadException e) {
// TODO: handle exception
System.out.println("没有获取到文件");
return null;
}
}else {
System.out.println("没有获取到文件");
return null;
}
}
/*
这个函数的功能是将文件传到预先设置的绝对路径中,也就是项目里的imgs文件夹
*/
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;
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
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");
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel);
Part part = request.getPart("pic");
String fileName = photoDao.getPhotoNewName();
String savePath = request.getSession().getServletContext().getRealPath("/imgs");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\imgs";
System.out.println("保存路径:"+savePath);
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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 login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
String zhanghao = request.getParameter("zhanghao");
String mima = request.getParameter("mima");
GuanliyuanDao guanliyuanDao = new GuanliyuanDao();
String psw =guanliyuanDao.getPassword(zhanghao);
if(psw ==null){
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
if(psw!=null&&!psw.equals(mima)){
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
if(psw.equals(mima)){
request.getRequestDispatcher("/admin.jsp").forward(request, response);
//response.setHeader("Refresh","1;url=welcome.jsp");
}
}
/*查找用户消息*/
protected void finf_UserXiaoxi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
}
}
/*招领*/
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");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\imgs";
System.out.println("保存路径:"+savePath);
File f = new File(savePath+"/");
if(!f.exists()) {
f.mkdirs();
}
part.write(savePath+"/"+fileName);
// 处理敏感词问题
// String t = getServletContext().getRealPath("/sensitiveWords.txt");
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);
Date d = new Date();
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");
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel);
Part part = request.getPart("pic");
String fileName = photoDao.getPhotoNewName();
String savePath = request.getSession().getServletContext().getRealPath("/imgs");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\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);
// 处理敏感词问题
String t = request.getSession().getServletContext().getRealPath("sensitiveWords.txt");
// String t = 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);
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
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");
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel);
Part part = request.getPart("pic");
String fileName = photoDao.getPhotoNewName();
request.getRequestDispatcher("/search-manager.jsp").forward(request, response);
}
}
// 删除招领信息
protected void deleteById_xiaoxi2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
XiaoxiDao xiaoxiDao = new XiaoxiDao();
String id = request.getParameter("id");
int idInt = Integer.parseInt(id);
int b = xiaoxiDao.delete(idInt);
if(b==1) {
request.getRequestDispatcher("/find-manager.jsp").forward(request, response);
}
}
}
package servlet;
/**
* Servlet implementation class UserServlet
*/
@WebServlet("/guanliyuanServlet")
public class GuanliyuanServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuanliyuanServlet() {
super();
// TODO Auto-generated constructor stub
}
String savePath = request.getSession().getServletContext().getRealPath("/imgs");
// String savePath = "D:\\eclipse\\SearchAndFindPlatform(源码)\\WebContent\\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);
// 处理敏感词问题
String t = request.getSession().getServletContext().getRealPath("sensitiveWords.txt");
// String t = 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);
Xiaoxi xiaoxi = new Xiaoxi();
xiaoxi.setZhuti(zhuti);
xiaoxi.setNeirong(newNeirong);
xiaoxi.setShijian(dateNow);
xiaoxi.setWupin(wupin);
xiaoxi.setLianxiren(lianxiren);
xiaoxi.setTel(tel);
xiaoxi.setImagesName(fileName);
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel+" "+"\n"+fileName);
XiaoxiDao xiaoxiDao = new XiaoxiDao();
int b=xiaoxiDao.insertsearch(xiaoxi);
if(b==1) {
request.getRequestDispatcher("/index.jsp").forward(request, response);
xiaoxi = xiaoxiDao.findmohuAll("%"+zhuti+"%");
System.out.println("%"+zhuti+"%");
if(xiaoxi==null){
request.setAttribute("msg", "没有该物品信息!");
request.getRequestDispatcher("/found.jsp").forward(request, response);
} else {
request.setAttribute("zhuti", zhuti);
request.setAttribute("xiaoxi", xiaoxi);
request.getRequestDispatcher("/found.jsp").forward(request, response);
//response.setHeader("Refresh","1;url=welcome.jsp");
}
}
// 删除寻物信息
protected void deleteById_xiaoxi1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
XiaoxiDao xiaoxiDao = new XiaoxiDao();
String id = request.getParameter("id");
int idInt = Integer.parseInt(id);
int b = xiaoxiDao.delete(idInt);
if(b==1) {
request.getRequestDispatcher("/search-manager.jsp").forward(request, response);
}
}
// 删除招领信息
protected void deleteById_xiaoxi2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
XiaoxiDao xiaoxiDao = new XiaoxiDao();
String id = request.getParameter("id");
int idInt = Integer.parseInt(id);
int b = xiaoxiDao.delete(idInt);
if(b==1) {
request.getRequestDispatcher("/find-manager.jsp").forward(request, response);
}
}
}
package servlet;
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuanliyuanServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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 login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
String zhanghao = request.getParameter("zhanghao");
String mima = request.getParameter("mima");
GuanliyuanDao guanliyuanDao = new GuanliyuanDao();
String psw =guanliyuanDao.getPassword(zhanghao);
if(psw ==null){
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
if(psw!=null&&!psw.equals(mima)){
public XiaoxiServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
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");
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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 login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("GB2312");
String zhanghao = request.getParameter("zhanghao");
String mima = request.getParameter("mima");
GuanliyuanDao guanliyuanDao = new GuanliyuanDao();
String psw =guanliyuanDao.getPassword(zhanghao);
if(psw ==null){
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
if(psw!=null&&!psw.equals(mima)){
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
if(psw.equals(mima)){
request.getRequestDispatcher("/admin.jsp").forward(request, response);
//response.setHeader("Refresh","1;url=welcome.jsp");
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateNow = sdf.format(d);
// 处理敏感词问题
String t = request.getSession().getServletContext().getRealPath("sensitiveWords.txt");
// String t = 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);
Xiaoxi xiaoxi = new Xiaoxi();
xiaoxi.setZhuti(zhuti);
xiaoxi.setNeirong(newNeirong);
xiaoxi.setShijian(dateNow);
xiaoxi.setWupin(wupin);
xiaoxi.setLianxiren(lianxiren);
xiaoxi.setTel(tel);
xiaoxi.setImagesName(fileName);
// System.out.println(zhuti+" "+neirong+" "+wupin+" "+lianxiren+" "+tel+" "+"\n"+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");
/**
* @see HttpServlet#HttpServlet()
*/
public XiaoxiServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
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");
/**
* Servlet implementation class UserServlet
*/
@WebServlet("/guanliyuanServlet")
public class GuanliyuanServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuanliyuanServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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);
}
}
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) {
// TODO: handle exception
System.out.println("没有获取到文件");
return null;
}
}else {
System.out.println("没有获取到文件");
return null;
}
}
/*
这个函数的功能是将文件传到预先设置的绝对路径中,也就是项目里的imgs文件夹
*/
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;
}
/*
这个函数的功能是获取当前时间点与1970年的间隔秒数
*/
public static int getSecondTimestamp(Date date){
if (null == date) {
return 0;
}
String timestamp = String.valueOf(date.getTime());
/**
* Servlet implementation class UserServlet
*/
@WebServlet("/guanliyuanServlet")
public class GuanliyuanServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuanliyuanServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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);
}
}
/**
* Servlet implementation class UserServlet
*/
@WebServlet("/guanliyuanServlet")
public class GuanliyuanServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuanliyuanServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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();
/**
* Servlet implementation class UserServlet
*/
@WebServlet("/guanliyuanServlet")
public class GuanliyuanServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuanliyuanServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
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);
}