uploadservlet.java

来自「新闻发布系统」· Java 代码 · 共 62 行

JAVA
62
字号
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 = new SmartUpload();
		int count = 0;
		try 
		{
			//上传到服务器的路径
			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.initialize(config,request,response);
			mySmartUpload.upload();			
			count = mySmartUpload.save(saveDirectory);
			
			//response.sendRedirect(backpath);

		}catch (Exception e){System.out.println("UploadServlet处理时出错;错误为:"+e);}
    }
	
	public void  destroy () 
	{
	}
} 

⌨️ 快捷键说明

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