protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); // 管理员登陆状态校验 UserVo user1 = (UserVo) request.getSession().getAttribute("user"); if (user1 == null) { out.print("<script>alert('登录状态错误,请重新登录');window.location.href='/login';</script>"); return; } String href = ""; UserVo user = new UserVo(); user = (UserVo) request.getSession().getAttribute("user"); ComplainVo compvo = new ComplainVo(); ComplainDao compdao = ComplainDaoImpFactory.getCompDaoImp(); // 拿到jsp页面传来的参数 int bookid = Integer.parseInt(request.getParameter("bookid")); String appeal = request.getParameter("appeal"); compvo.setUserid(user.getId()); compvo.setBookid(bookid); compvo.setDescription(appeal); // 往数据库里添加申诉信息 try { compdao.addAppeal(compvo); } catch (SQLException e) { e.printStackTrace(); } href = "/addAppeal"; out.print( "<script language='javascript'>alert('发布申诉成功');" + "window.location.href='" + href + "';</script>"); }
/** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(true); Integer userID = new Integer(-1); // UserVo userVo = new UserVo(1, "nihao", "nihao", "/SH_Books/images/touxiang.png", "nihao", 1, // "2015-01-01", "nihao", "nihao", 0); UserVo userVo; userVo = (UserVo) session.getAttribute("user"); // 从session中拿到vo if (userVo == null) { // 失败则提醒登录 out.print("<script>alert('你的登陆状态出错');window.location.href='/login';</script>"); return; } userID = userVo.getId(); // 用get拿到id*/ session.setAttribute("userID", userID); // 传参 String href = ""; // 跳转的界面 String strPage = request.getParameter("thisPage"); // 首次strPage=null System.out.print(strPage); session.setAttribute("thisPage", strPage); InformDao InformDaoImpl = InformDaoImplFactory.getInformDaoImpl(); List<InformVo> informs = null; List<InformVo> list = null; List<InformVo> wants = null; List<InformVo> unread = null; List<InformVo> manager = null; try { informs = (List<InformVo>) InformDaoImpl.findbyuserid(userID); unread = (List<InformVo>) InformDaoImpl.count(userID); wants = (List<InformVo>) InformDaoImpl.findallbyut(userID, 1); list = (List<InformVo>) InformDaoImpl.findallbyut(userID, 2); manager = (List<InformVo>) InformDaoImpl.manager(userID); } catch (SQLException e) { e.printStackTrace(); } session.setAttribute("informs", informs); // all 通知 session.setAttribute("list", list); // 订单通知 session.setAttribute("wants", wants); // 心愿单通知 session.setAttribute("unread", unread); // 未读通知 session.setAttribute("manager", manager); // 系统通知 if (informs != null) { try { InformDaoImpl.close(); // 关闭连接 } catch (SQLException e) { e.printStackTrace(); } href = "/inform"; // 跳转至jsp显示表单内容 out.print( "<script language='javascript'>window.location.href='" + href + "';</script>"); // 页面重定向 } else { href = "/controlCenter"; out.print( "<script language='javascript'>alert('暂无通知消息,先去别的地方转转吧~~');window.location.href='" + href + "';</script>"); try { InformDaoImpl.close(); } catch (SQLException e) { e.printStackTrace(); } } out.flush(); out.close(); }