在用struts2上传文件时,总是取不到文件名.
<input type="file" name="uploadSummary />
在action类定义文件的三个属性
private File uploadSummary;
private String uploadFileName;
private String uploadContentType;
private String savePath; //在xml文件中已指定
在上传时,总是取不到文件名,文件名null,开始以为是拦截器的问题,使用struts2自带的拦截器,还是取不到。后来上网查资料,问题总于解决了,原来时file 的名称只能是upload
即<input type="file" name="upload />,这样写问题就解决了.
<input type="file" name="uploadSummary />
在action类定义文件的三个属性
private File uploadSummary;
private String uploadFileName;
private String uploadContentType;
private String savePath; //在xml文件中已指定
在上传时,总是取不到文件名,文件名null,开始以为是拦截器的问题,使用struts2自带的拦截器,还是取不到。后来上网查资料,问题总于解决了,原来时file 的名称只能是upload
即<input type="file" name="upload />,这样写问题就解决了.
本文解决使用Struts2上传文件时取不到文件名的问题,发现原因在于文件输入标签的name属性设置不当。通过将标签的name属性更改为'upload'而非'uploadSummary/',成功解决问题。
4957

被折叠的 条评论
为什么被折叠?



