Struts2 2.3.1.2上传方式的改变

今天我们的Struts2突然更新了,不知道怎么的,不能用以前的上传方式同时上传图片和文字。后面看官网,原来sun公司为了提高上传速度而进行了优化。页面和以前的一样,我就不贴代码,主要是服务器端,代码如下:
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
factory.setRepository(new File(realpath));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(4*1024*1024);
HttpServletRequest request = super.getRequest();
List<FileItem> fileItems = upload.parseRequest(request);
Iterator i= fileItems.iterator();
while(i.hasNext()){
FileItem fi=(FileItem) i.next();
if (fi.isFormField()) {
String fieldname = fi.getFieldName();
String fieldvalue = fi.getString("UTF-8");

if (fieldname.equalsIgnoreCase("parentBiz.PId")) {
parentBiz.setPId(Long.valueOf(fi.getString()));
}
if(fieldname.equalsIgnoreCase("parentBiz.familyid")){
parentBiz.setFamilyid(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.familyName")){
parentBiz.setFamilyName(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.sscs")){
parentBiz.setSscs(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.fuserZh")){
parentBiz.setFuserZh(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.picTime")){
parentBiz.setPicTime(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.classMode")){
parentBiz.setClassMode(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.picMode")){
parentBiz.setPicMode(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.xtCzrxm")){
parentBiz.setXtCzrxm(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.xtCzsj")){
parentBiz.setXtCzsj(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.xtZhxgrxm")){
parentBiz.setXtZhxgrxm(fi.getString());
}
if(fieldname.equalsIgnoreCase("parentBiz.xtZhxgsj")){
parentBiz.setXtZhxgsj(fi.getString());
}

}
if (!fi.isFormField()) {
String FileName = fi.getName();
File fia = new File(realpath+parentBiz.getPId()+".jpg");
if(fia.exists()){
fia.delete();
}

fi.write(new File(realpath+parentBiz.getPId()+".jpg"));
}
}
}catch(Exception e){
e.printStackTrace();
}

你可能感兴趣的:(struts2)