从SmartUpload到FileUpload的无缝转移
时间:2010-12-14 javaeye sunnodbird
在修改项目时,发现以前的jsp项目,附件上传用的是SmartUpload,系统中 多处都用的是这这种方式上传,这种上传附件的机制大小只能传十兆左右,
而客户现在要求,至少50M,所以原有的SmartUpload不能满足需求,所以打 算用Fileupload来实现附件上传功能。但如果换FileUpload,则系统代码改动量 很大,大概有50于处地方都需要修改,遂放弃,直接修改代码的想法。
于是,看了一些代码后,自己写了一个从SmartUload到FileUpload转接的中 间件程序,可实现不用修改原有SmartUpload上传的代码。
原上传的主要代码见下面:
Java代码
SmartUpload objUpload = new SmartUpload(pageContext);
///主要代码
if(objUpload.getCount()>0)
{
for(int i=1;i<=objUpload.getCount();i++){
ps.setString(9,objUpload.getUgetContentType (i));
ps.setString(10,objUpload.getUFileName(i));
ps.setBinaryStream (11,objUpload.getUFileInputStream(i), objUpload.getFLength (i));//Content
}
}
貫SmartUpload欺FileUpload議涙血廬卞(2)
扮寂:2010-12-14 javaeye sunnodbird
厘亟議嶄寂周窃?窃兆匆出SmartUpload?徽喘議頁Fileupload貧勧議字崙?
Java旗鷹
package gui;
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.servlet.*;
import org.apache.commons.fileupload.disk.*;
// Referenced classes of package gui:
// SmartFiles, SmartRequest, SmartUploadException, SmartFile
public class SmartUpload
{
protected Hashtable parameters;//隠贋噸宥form燕汽囃
protected Hashtable files;//隠贋貧勧議猟周
private int sizeThreshold = 4096;
public int maxflag=0;
private long filemaxsize=100*1024*1024; //潮範100MB
protected HttpServletRequest m_request;
protected HttpServletResponse m_response;
protected ServletContext m_application;
private PageContext page;
private String pencoding;
public SmartUpload()
{
}
//更夛圭隈 歌方匯 pagecontex 歌方屈 匯違葎GBK 歌方眉 貧勧議恷寄猟周 汽了MB
public SmartUpload(PageContext pagecontext,String encoding,long filesize)
throws ServletException, IOException,FileUploadException
{
page=null;
page=pagecontext;
m_request=(HttpServletRequest)page.getRequest();
m_response=(HttpServletResponse)page.getResponse();
if(encoding==null||"".equals(encoding)) encoding="GBK";
this.pencoding=encoding;
if(filesize
|