ModifyNews.java
上传用户:junmaots
上传日期:2022-07-09
资源大小:2450k
文件大小:3k
- /*
- * Created on 2005-12-10
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
- package com.mycompany.servlet;
- import java.io.IOException;
- import java.net.URLEncoder;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.jspsmart.upload.Request;
- import com.jspsmart.upload.SmartUpload;
- import com.jspsmart.upload.SmartUploadException;
- import com.mycompany.news.dto.News;
- import com.mycompany.news.service.NewsService;
- /**
- * @author Administrator
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
- public class ModifyNews extends HttpServlet {
-
- private ServletConfig config;
- public void init(ServletConfig arg0) throws ServletException {
- config = arg0;
- }
- protected void service(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- SmartUpload upload = new SmartUpload();
- try
- {
- upload.initialize(config, request, response);
- // 允许上传的文件类型
- // upload.setAllowedFilesList("doc,xls,");
- // 拒绝上传的文件类型
- // upload.setDeniedFilesList("exe,bat,jsp");
- // 允许上传文件的单个最大大小
- upload.setMaxFileSize(1024 * 1024 * 20);
- // 允许上传文件的最大大小总和
- // upload.setTotalMaxFileSize(1024*1024*10);
- //上传数据
- upload.upload();
- }
- catch (SmartUploadException e){
- e.printStackTrace();
- return;
- }
- Request req = upload.getRequest();
- Long columnId = Long.valueOf(req.getParameter("columnId"));
- Long newsId = Long.valueOf(req.getParameter("newsId"));
- String subject = req.getParameter("subject");
- String content = req.getParameter("content");
- String author =req.getParameter("author");
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- Date showTime=new Date();
- try {
- showTime=sdf.parse(req.getParameter("showTime"));
- } catch (ParseException e1) {
- e1.printStackTrace();
- }
- String source = req.getParameter("source");
- News news = new News();
- news.setNewsId(newsId);
- news.setAuthor(author);
- news.setColumnId(columnId);
- news.setContent(content);
- news.setNewsStatus(new Integer(0));
- news.setShowTime(showTime);
- news.setSubject(subject);
- NewsService nservice = new NewsService();
- boolean result = nservice.modifyNews(news,upload);
-
- if(result)
- response.sendRedirect(request.getContextPath()+"/opsucc.jsp?message="+URLEncoder.encode(nservice.getMessage(),"GB2312"));
- else
- response.sendRedirect(request.getContextPath()+"/opfail.jsp?message="+URLEncoder.encode(nservice.getMessage(),"GB2312"));
- }
- }