@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); User user = (User) session.getAttribute("user"); Comment comment = new Comment(); comment.setUserId(user.getUserId()); comment.setNewsId(Integer.parseInt(request.getParameter("news"))); comment.setText(request.getParameter("text")); MessagesBundle messagesBundle = new MessagesBundle(); String errorMessage = messagesBundle.getMessages().get("addCommentFailed"); try { commentService.addComment(comment); List<News> allNews = newsService.getAllNews(user.getUserId()); List<List<Comment>> allComments = commentService.getAllBy(allNews); session.setAttribute("allComments", allComments); response.sendRedirect("/home.jsp"); } catch (DAOException e) { LOGGER.error("Database connection problem", e); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/home.jsp"); request.setAttribute("errorMessage", errorMessage); dispatcher.include(request, response); } }
@RequestMapping(value = "c_delete.do") public String deleteComment(int commentNo) { int articleNo = service.readComment(commentNo).getArticleNo(); if (service.deleteComment(commentNo)) { return "redirect:read.do?articleNo=" + articleNo; } else { return "redirect:error.do"; } }
@RequestMapping(value = "c_rewrite.do") public String reWriteComment(int commentNo, String commentContent) { if (service.reWriteComment(commentNo, commentContent)) { int articleNo = service.readComment(commentNo).getArticleNo(); String result = "redirect:read.do?articleNo=" + articleNo; return result; } else { return "redirect:error.do"; } }
@RequestMapping(value = "c_rewrite_form.do") public ModelAndView reWriteCommentForm(int commentNo) { Comment originalComment = service.readComment(commentNo); ModelAndView mv = new ModelAndView(); mv.setViewName("c_rewrite_form"); mv.addObject("originalComment", originalComment); return mv; }
@RequestMapping(value = "c_write.do", method = RequestMethod.POST) public String CommentWrite(Comment comment) { System.out.println("코멘트.코멘트컨텐트 : " + comment.getCommentContent()); if (service.writeComment(comment)) { String result = null; result = "redirect:read.do?articleNo=" + comment.getArticleNo(); return result; } else { return "redirect:error.do"; } }