Struts2下传文件再分解
Struts2上传文件再分解
因公司开发项目要做Struts2上传文件,前台是通过flex实现所以再现有代码基础上又深入改进了一下,先转一下别人的代码,我们的回头二次改造好后在放上来。
public void preExecute() { if (httpServletRequest instanceof MultiPartRequestWrapper) { MultiPartRequestWrapper requestWrapper = (MultiPartRequestWrapper) httpServletRequest; Enumeration<String> parameterNames = requestWrapper.getFileParameterNames(); while (parameterNames.hasMoreElements()) { @SuppressWarnings("unused") String paramterName = parameterNames.nextElement(); File[] files = requestWrapper.getFiles(paramterName); if (null == files || files.length == 0) { continue; } else if (files.length == 1) { FileBean fileBean = new FileBean(); fileBean.setAbsolutePath(files[0].getAbsolutePath()); fileBean.setFileSize(files[0].length()); fileBean.setFilename(requestWrapper.getFileNames(paramterName)[0]); this.fileMap.put(paramterName, fileBean); } else { ArrayList<FileBean> list = new ArrayList(); for (int i = 0; i < files.length; i++) { File file = files[i]; FileBean fileBean = new FileBean(); fileBean.setAbsolutePath(file.getAbsolutePath()); fileBean.setFileSize(file.length()); fileBean.setFilename(requestWrapper.getFileNames(paramterName)[i]); list.add(fileBean); } this.fileMap.put(paramterName, list); } } } }转自http://sdh88hf.iteye.com/?show_full=true