您的位置:首页 > Web前端 > JavaScript

使用 SmartUpload 在jsp中上传文件

2010-07-07 16:02 239 查看
//***************************************文件上传begin*******************************************//
String loadFlag = (String)request.getParameter("loadFlag");
String uploadpath = "";
String outtext = "";
String title = "";
String keywords = "";
String localtext = "";
if(loadFlag != null && !loadFlag.equals(""))
{
loadFlag = "1";
//获得路径
String localpath = PropertiesReader.getValueOf("/application.sm.properties","sm.knowledge_path");
if(localpath == null) localpath = "";

SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");
String localTime = sdf.format(new Date());

// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();

// 上传初始化
su.initialize(pageContext);

// 上传文件
su.upload();
for (int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
// 若文件存在则继续
if (!file.isMissing())
{
String theFileName = file.getFileName();
String thisFileName =localTime;
String theExtName = theFileName.substring(theFileName.lastIndexOf(".") + 1, theFileName.length());
outtext = thisFileName + "." + theExtName;
request.setAttribute("outtext",outtext);
file.saveAs(localpath + outtext, su.SAVE_PHYSICAL);
}
}

title = su.getRequest().getParameter("title");
if(title == null)
{
title = "";
}
System.out.println(title);
keywords = su.getRequest().getParameter("keywords");
if(keywords == null )
{
keywords = "";
}
localtext = su.getRequest().getParameter("localtext");
if(localtext == null)
{
localtext = "";
}
localtext = new String(localtext.getBytes());
}else
{
loadFlag = "0";
}
//*********************************************文件上传end************************************************//
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: