📄 uploadservlet.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 + -