该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
哟 SmartUpLoad 中国人写的上传下载的一个模板。
SmartUpload smartUpload=new SmartUpload();
//Common
//paraseRequest();
ServletConfig config=this.getServletConfig();
smartUpload.initialize(config, request, response);
try {
smartUpload.upload();//parseRquest(request);
} catch (SmartUploadException e) {
e.printStackTrace();
}
//HttpServletRequest不是一个东西
//SmartUpload自己封装的
//内部维护了一个hashmap
//简单控件中的值都封装在了hashmap中
Request req=smartUpload.getRequest();
String proName=req.getParameter("proName");
String strProPrice=req.getParameter("proPrice");
double proPrice=new Double(strProPrice);
String proDis=req.getParameter("proDis");
//文件
Files fs=smartUpload.getFiles();
int size=fs.getCount();
String imageUrl="";
for (int i = 0; i < size; i++) {
File f=fs.getFile(i);
String fieldName=f.getFieldName();//控件名字
String pathName=f.getFilePathName();//文件名字
//c:/hello/hello.gif
//此处需要处理,有可能得到的是一个文件的路径....
System.out.println(fieldName+" ---- "+pathName);
imageUrl+="img/"+pathName+",";
String realPath=request.getRealPath("/img/"+pathName);
System.out.println(realPath);
try {
f.saveAs(realPath);//把文件保存在服务器磁盘上.....
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
imageUrl=imageUrl.substring(0,imageUrl.length()-1);
System.out.println(imageUrl);//真是路径