使用oreilly上传组件上传文件


public class fileOreilly extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String saveDirectory = "D:\\Upload\\";//文件上传的地址
		String encoding = "UTF-8";
		int maxPostSize = 5*1024*1024;//文件大小
		String fileName = null;
		String contentType = null;
		String description = null;
		MultipartRequest multi = new MultipartRequest(request,saveDirectory,maxPostSize,encoding);
		int count = 0;
		Enumeration fileName2 = multi.getFileNames();
		Enumeration filesdc = multi.getParameterNames();	
		while(fileName2.hasMoreElements()){
			String name = (String)fileName2.nextElement();
			String dc = (String)filesdc.nextElement();
			fileName = multi.getFilesystemName(name);
			contentType = multi.getContentType(name);
			description = multi.getParameter(dc);
			if(fileName !=null){
				count++;
			}
			response.getWriter().println("您上传的第"+count+"个文件");
			response.getWriter().println("文件名称为:"+fileName);
			response.getWriter().println("文件类型为:"+contentType);
			response.getWriter().println("文件的描述"+description);
		}
		response.getWriter().println("你总共上传"+count+"个文件");
		
	}

}


其实oreilly是一个过时的开源组件,我之所以会学它主要是因为JavaMail中的使用
oreilly上传组件总共有八个构造函数,上面列举的是最常用的一种,如果想要演示示例以及所有的构造方法详解,请E-mail 给我 [email protected]! 谢谢

你可能感兴趣的:(qq)