AddComment.java
上传用户:junmaots
上传日期:2022-07-09
资源大小:2450k
文件大小:2k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. /*
  2.  * Created on 2005-12-9
  3.  *
  4.  * TODO To change the template for this generated file go to
  5.  * Window - Preferences - Java - Code Style - Code Templates
  6.  */
  7. package com.mycompany.servlet;
  8. import java.io.IOException;
  9. import java.net.URLEncoder;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. import com.mycompany.news.dto.NewsComment;
  15. import com.mycompany.news.service.NewsCommentService;
  16. /**
  17.  * @author Administrator
  18.  *
  19.  * TODO To change the template for this generated type comment go to
  20.  * Window - Preferences - Java - Code Style - Code Templates
  21.  */
  22. public class AddComment extends HttpServlet {
  23. protected void service(HttpServletRequest request, HttpServletResponse response)
  24. throws ServletException, IOException {
  25. String commentPerson = request.getParameter("commentPerson");
  26. String commentSubject= request.getParameter("commentSubject");
  27. String commentContent= request.getParameter("commentContent");
  28. long newsId = Long.parseLong(request.getParameter("newsId"));
  29. String fromAddress = request.getRemoteAddr();
  30. NewsCommentService cs = new NewsCommentService();
  31. NewsComment comment= new NewsComment();
  32. comment.setAuditStatus(0);
  33. comment.setCommentContent(commentContent);
  34. comment.setCommentPerson(commentPerson);
  35. comment.setCommentSubject(commentSubject);
  36. comment.setFromAddress(fromAddress);
  37. comment.setNewsId(new Long(newsId));
  38. if(cs.addComment(comment))
  39. response.sendRedirect(request.getContextPath()+"/opsucc.jsp?message="+URLEncoder.encode(cs.getMessage(),"GB2312"));
  40. else
  41. response.sendRedirect(request.getContextPath()+"/opfail.jsp?message="+URLEncoder.encode(cs.getMessage(),"GB2312"));
  42. }
  43. }