顶一下了,看来高人都在想着怎么过年了
解决方案 »
- 求解。Hibernate的优势。
- 通过传过来value的值让select下的option默认选中!不能用jquery
- Struts中logic:iterate 获取上个页面的List问题
- XML 部署 Servlet 问题
- 怎样使用html中的choice控件
- Connection的回收,JavaBean写连接池,请指教,分奉上!
- <logic equal >
- 请教哥哥,下载邮件附件程序怎样写?用jsp
- JBoss提示以下信息:请问是出了什么问题?如何解决,谢谢各位老大了!
- 启动tomcat4.0.3遇到的错误?这种情况应如何解决,谢谢!!
- 请问如何从HTML文件中抽取出文本内容来。谢谢,急!
- 在jsp中能不能,调用word来代替文本框编辑内容?
思考!
import com.jspsmart.upload.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import new.com.website.vo.voConfig;
import new.com.website.bean.systemmanage.configManage.web_Config;//上传文件。
public class UploadUtil { private long maxSize;//最大字节数(B)
private String path;//存储路径(绝对路径,包括主文件名,不包括括展名)
private String format;//文件格式
private PageContext pageContext;
private com.jspsmart.upload.SmartUpload smartUpload;
private String primaryFileName;//主文件名
private String fileName;
private String relativePath;//相对路径
private String pathAndFileName; public UploadUtil()
{
this.smartUpload=new com.jspsmart.upload.SmartUpload();
}
public UploadUtil(PageContext pageContext)
{
this.smartUpload=new com.jspsmart.upload.SmartUpload();
this.pageContext=pageContext;
}
public UploadUtil(long maxSize,String path,String format,PageContext pageContext)
{
this.maxSize=maxSize;
this.path=path;
this.format=format;
this.pageContext=pageContext;
this.smartUpload=new com.jspsmart.upload.SmartUpload();
} public void setPrimaryFileName(String str)
{ this.primaryFileName=str;}
public String getPrimaryFileName()
{ return this.primaryFileName;}
public void setMaxSize(long n)
{ this.maxSize=n*1024;}
public long getMaxSize()
{ return this.maxSize;}
public void setPath(String str)
{ this.path=str;}
public String getPath()
{ return this.path;}
public void setFormat(String str)
{ this.format=str;}
public String getFormat()
{ return this.format;}
public void setPageContext(PageContext obj)
{ this.pageContext=obj;}
public String getFileName()
{ return this.fileName;}
public void setRelativePath(String str)
{ this.relativePath=str;}
public String getRelativePath()
{ return this.relativePath;}
public Request getRequest()
{ return this.smartUpload.getRequest();}
public String getAbsolutePathAndFileName()
{
return this.pathAndFileName;
}
public String getRelativePathAndFileName()
{
return this.relativePath.trim()+this.fileName;
} public boolean upload()
{
boolean result=false;
try
{
smartUpload.initialize(pageContext);
smartUpload.setMaxFileSize(this.maxSize);
smartUpload.setAllowedFilesList(this.format);
smartUpload.upload(); com.jspsmart.upload.File file=smartUpload.getFiles().getFile(0);
if(file.getSize()>this.maxSize)
throw new Exception("文件太大。");
if(file.getSize()==0&&file.getFileExt().equals(""))
{
throw new Exception("上传失败!");
}
file.saveAs(this.path+"."+file.getFileExt().toLowerCase());
this.fileName=new java.io.File(this.path+"."+file.getFileExt().toLowerCase()).getName();
this.pathAndFileName=new java.io.File(this.path+"."+file.getFileExt().toLowerCase()).getPath();
result=true;
}
catch(Exception e)
{
result=false;
e.printStackTrace();
}
return result;
}public boolean defaultUpload(String str)
{
if(str.charAt(str.length()-1)!='\\'||str.charAt(str.length()-1)!='/')
str=str+"\\";
voConfig conf=new web_Config().voGet_Config_Info();
this.relativePath=conf.getUpload_file_path().trim();
this.maxSize = conf.getUpload_file_size()*1024;
this.primaryFileName=String.valueOf(new java.util.Date().getTime());
this.path =str+DoFile.doString(this.relativePath)+this.primaryFileName;
this.format = conf.getUpload_file_type().trim()+",";
return this.upload();
}
}