⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadservlet.java

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -