`
jamesby
  • 浏览: 380890 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

是用SmartUpload进行文件上传

    博客分类:
  • Java
阅读更多
package com.jamesby.file.servlet;

public class UpLoadServlet extends HttpServlet {
	private static Log log = LogFactory.getLog(UpLoadServlet.class);
	
	private ServletConfig config;
	
	final public void init(ServletConfig config) throws ServletException {
		this.config = config;
	}
	
	final public ServletConfig getServletConfig() {
		return config;
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws
	ServletException, IOException {
		doPost(request, response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response) throws
	ServletException, IOException {
		try {
			SmartUpload su = new SmartUpload();
			
			su.initialize(config, request, response);
			
			su.setMaxFileSize(1024 * 1024 * 4); //4M
			
			su.upload();
			
			String paramValue = su.getRequest().getParameter("paramName");
			
			String path = "d:/upload";
			for (int i = 0; i < su.getFiles().getCount(); i++) {
				
				com.jspsmart.upload.File file = su.getFiles().getFile(i);
				
				String fileName = file.getFileName();
				
				if (!file.isMissing())  file.saveAs(path + "/"+fileName,SmartUpload.SAVE_PHYSICAL);
				else continue;
			}
			return null;
		} catch (Exception ex) {
		
		}
	}
}


分享到:
评论
1 楼 hua839 2009-09-05  
      

相关推荐

Global site tag (gtag.js) - Google Analytics