package servlet;
import java.io.IOException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
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 bean.Xiaoxi;
import dao.XiaoxiDao;
/**
* Servlet implementation class XiaoxiServlet
*/
@WebServlet("/xiaoxiServlet")
public class XiaoxiServlet extends HttpServlet {
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 {
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");
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(neirong);
xiaoxi.setShijian(dateNow);
xiaoxi.setWupin(wupin);
xiaoxi.setLianxiren(lianxiren);
xiaoxi.setTel(tel);
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");
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(neirong);
xiaoxi.setShijian(dateNow);
xiaoxi.setWupin(wupin);
xiaoxi.setLianxiren(lianxiren);
xiaoxi.setTel(tel);
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");
}
}
}