SmartUpload文件上传

<body background="images/0005.jpg"> 
<center> 
<h2>您好,您已经成功登陆!可以随时上传文件 </h2> 
<form action="UpLoadServlet" method="post" enctype="multipart/form-data"> 
上传: <input type="file" name="file1"> <br> 
上传: <input type="file" name="file2"> <br> 

<input type=submit value="上传"> <br> 
<br> <br> 
</form> 
</center> 
</body> 

</html>



protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=gb2312"); 
		PrintWriter out = response.getWriter(); 
		System.out.println("1"); 
		//创建文件上传的上传器 
		SmartUpload su = new SmartUpload(); 
		//初始化上传对象 
		su.initialize(this.getServletConfig(), request, response); 
		//配置上传参数:每个用户最大容量为5M 
		su.setTotalMaxFileSize(1024*1024*5); 
		//设定允许上传的文件 
		su.setAllowedFilesList("doc,txt,jpg"); 
		//上传文件至缓冲区 
		try { 
		System.out.println("2"); 
		su.upload(); 
		System.out.println("3"); 
		} catch (SmartUploadException e) { 
		e.printStackTrace(); 
		} 

		for (int i = 0; i < su.getFiles().getCount(); i++) { 
			System.out.println(su.getFiles().getCount());
		com.jspsmart.upload.File file = su.getFiles().getFile(i); 
		try { 
		file.saveAs("D:\\7777\\" + file.getFileName()); 
		} catch (SmartUploadException e) { 
		e.printStackTrace(); 
		} 
		} 
		System.out.println("4"); 
		//request.getRequestDispatcher("UpLoad.jsp?action=1").forward(request, response); 

		} 



 

你可能感兴趣的:(html,jsp)