File upload Struts 2文件上载-空指针异常

File upload Struts 2文件上载-空指针异常,file-upload,struts2,File Upload,Struts2,我正在尝试使用Struts2和Spring上传一个文件。但是,在到达action类之后,我的文件、文件名和文件内容类型都显示为null。我试图寻找这个问题,但没有结果。下面是我上传文件的代码 index.jsp: Struts.xml 10240 文本/纯文本 displayResultsJSP applicationContext-web.xml ManagePlanUploadAction 包com.hix.action.planmgmt; 导入java.io.File; 导入javax.s

我正在尝试使用Struts2和Spring上传一个文件。但是,在到达action类之后,我的文件、文件名和文件内容类型都显示为null。我试图寻找这个问题,但没有结果。下面是我上传文件的代码

index.jsp:

Struts.xml

10240 文本/纯文本 displayResultsJSP applicationContext-web.xml

ManagePlanUploadAction

包com.hix.action.planmgmt; 导入java.io.File; 导入javax.servlet.http.HttpServletRequest; 导入org.apache.commons.io.FileUtils; 导入com.opensymphony.xwork2.ActionSupport; 公共类ManagePlanUploadAction扩展了ActionSupport{ 私有HttpServletRequest; 私人文件上传; 私有字符串fileUploadContentType; 私有字符串fileUploadFileName; public void setServletRequestHttpServletRequest参数HttpServletRequest{ this.request=paramHttpServletRequest; } 公共HttpServletRequest getServletRequest{ 返回请求; } 公共文件getFileUpload{ 返回文件上传; } public void setFileUploadFile fileUpload{ this.fileUpload=fileUpload; } 公共字符串getFileUploadContentType{ 返回fileUploadContentType; } public void setFileUploadContentTypeString fileUploadContentType{ this.fileUploadContentType=fileUploadContentType; } 公共字符串getFileUploadFileName{ 返回fileUploadFileName; } public void setFileUploadFileNameString文件上传文件名{ this.fileUploadFileName=fileUploadFileName; } 公共字符串executeFileUploadDemo引发异常{ 试一试{ 字符串filePath=C:/Myuploads2; System.out.printlnServer路径:+filePath; File fileToCreate=new filepath,fileUploadFileName; FileUtils.copyFileUpload,fileToCreate; }卡奇{ e、 打印跟踪; addActionErrore.getMessage; 回归成功; } System.out.printlnFile:+fileUpload; System.out.printlnFilename:+fileUploadFileName; System.out.printlnFile type:+fileUploadContentType; 回归成功; } } tiles-def.xml

Result.jsp

文件名: 内容类型: 文件:
我的问题现在解决了。我必须将jars commons文件上传和commons io不仅添加到我的类路径中,还添加到RAD的部署程序集中

您的第一个JSP文件甚至没有元素。我会考虑更一致地构造/格式化您的源代码,并且只包括必要的最低限度来传达您正在做的事情。此外,除非您有非常特定的需要,否则不要指定名称配置文件struts-Debug .xml和/或B,如果它是框架的Struts默认值,则显式包含它。这就是为什么这么叫。谢谢戴夫,我以后会考虑这些的。