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

Jsp/Servlet

开发平台:

Java

  1. /*
  2.  * Created on 2005-12-10
  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 java.text.ParseException;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Date;
  13. import javax.servlet.ServletConfig;
  14. import javax.servlet.ServletException;
  15. import javax.servlet.http.HttpServlet;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18. import com.jspsmart.upload.Request;
  19. import com.jspsmart.upload.SmartUpload;
  20. import com.jspsmart.upload.SmartUploadException;
  21. import com.mycompany.news.dto.News;
  22. import com.mycompany.news.service.NewsService;
  23. /**
  24.  * @author Administrator
  25.  *
  26.  * TODO To change the template for this generated type comment go to
  27.  * Window - Preferences - Java - Code Style - Code Templates
  28.  */
  29. public class ModifyNews extends HttpServlet {
  30. private ServletConfig config;
  31. public void init(ServletConfig arg0) throws ServletException {
  32. config = arg0;
  33. }
  34. protected void service(HttpServletRequest request, HttpServletResponse response)
  35. throws ServletException, IOException {
  36. SmartUpload upload = new SmartUpload();
  37. try
  38.     {
  39. upload.initialize(config, request, response);
  40. // 允许上传的文件类型
  41. // upload.setAllowedFilesList("doc,xls,");
  42. // 拒绝上传的文件类型
  43. // upload.setDeniedFilesList("exe,bat,jsp");
  44. // 允许上传文件的单个最大大小
  45. upload.setMaxFileSize(1024 * 1024 * 20);
  46. // 允许上传文件的最大大小总和
  47. // upload.setTotalMaxFileSize(1024*1024*10);
  48. //上传数据
  49. upload.upload();
  50. }
  51. catch (SmartUploadException e){
  52. e.printStackTrace();
  53. return;
  54. }
  55. Request req = upload.getRequest();
  56. Long columnId = Long.valueOf(req.getParameter("columnId"));
  57. Long newsId = Long.valueOf(req.getParameter("newsId"));
  58. String subject = req.getParameter("subject");
  59. String content = req.getParameter("content");
  60. String author =req.getParameter("author");
  61. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  62. Date showTime=new Date();
  63. try {
  64. showTime=sdf.parse(req.getParameter("showTime"));
  65. } catch (ParseException e1) {
  66. e1.printStackTrace();
  67. }
  68. String source = req.getParameter("source");
  69. News news = new News();
  70. news.setNewsId(newsId);
  71. news.setAuthor(author);
  72. news.setColumnId(columnId);
  73. news.setContent(content);
  74. news.setNewsStatus(new Integer(0));
  75. news.setShowTime(showTime);
  76. news.setSubject(subject);
  77. NewsService nservice = new NewsService();
  78. boolean result = nservice.modifyNews(news,upload);
  79. if(result)
  80. response.sendRedirect(request.getContextPath()+"/opsucc.jsp?message="+URLEncoder.encode(nservice.getMessage(),"GB2312"));
  81. else
  82. response.sendRedirect(request.getContextPath()+"/opfail.jsp?message="+URLEncoder.encode(nservice.getMessage(),"GB2312"));
  83. }
  84. }