uploadservlet.java

来自「用JSP+ORACLE写的 公司个人信息网络管理系统(JSP).」· Java 代码 · 共 74 行

JAVA
74
字号
package oa.servlet;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.jspsmart.upload.*;

public class UploadServlet extends HttpServlet 
{
	
	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);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		SmartUpload mySmartUpload = null;
		int count = 0;
		try 
		{
			mySmartUpload = new SmartUpload();
			mySmartUpload.initialize(config,request,response);	
			///////////////////////////////////////////////////
			mySmartUpload.setTotalMaxFileSize(10240000);
			////////////////////////////////////////////////////

			//上传到服务器的路径
			String saveDirectory = request.getRealPath("/")+"hg\\oa\\upload\\";

			String path = (String)mySmartUpload.getRequest().getParameter("PATH");
			String filepath =  request.getParameter("filepath");
			String backpath =  (String)mySmartUpload.getRequest().getParameter("backpath");

			
			//System.out.println("saveDirectory="+saveDirectory);
			//System.out.println("path="+path);
			//System.out.println("filepath="+filepath);
			//System.out.println("backpath="+backpath);


			mySmartUpload.upload();			
			count = mySmartUpload.save(saveDirectory);
			
			//response.sendRedirect(backpath);

		}catch (Exception e){System.out.println("UploadServlet处理时出错;错误为:"+e);}
		finally{
		//////////////////////////////////////////////////
			mySmartUpload.stop();
            mySmartUpload=null;
			System.gc();
			////////////////////////////////////////////////
		}
    }
	
	public void  destroy () 
	{
	}
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?