日期:2014-05-17  浏览次数:20926 次

FROM使用enctype="multipart/form-data"属性后,后台获得null值。
以下代码在tomcat环境下没有问题。但是在weblogic环境下后台实体类获得的值为null那位高手可以帮忙解答以下,谢谢
页面代码:
<form name="listForm" action="notice!save.action" method="POST"  enctype="multipart/form-data" >
<table border="1" width="100%" cellspacing="1" cellpadding="2" align="center" class="table_edit_border">
<!--<input type="hidden" name="notice.ncid" value="<ww:property value="notice.ncid"/>"/>-->
<tr>
        <td class="table_edit_cell_border" width="21%" align="right" class="tdbg" height="25" ><font color="red">*</font>标&nbsp;&nbsp;&nbsp;&nbsp;题:</td>
        <tr>
        <td class="table_edit_cell_border" width="21%" align="right" class="tdbg" height="25" >附&nbsp;&nbsp;&nbsp;&nbsp;件:</td>
     <td class="table_edit_cell_border" width="79%"  title="附件" colspan="2" class="tdbg"><input type="file" name="upload" style="800px;" /></td>
</tr>
</table>
</form>
---------------------------------------------

后台代码:
public String save() {
try {
if (upload != null) {
String path_ = ServletActionContext.getRequest().getSession()
.getServletContext().getRealPath("/");
try {
System.out.println(uploadFileName+"---====");
FileUtils.createPaths(path_ + "uploaddir\\");
FileUtils.copyFile(upload, path_ + "uploaddir\\"
+ uploadFileName);
} catch (FileUtilException e) {
e.printStackTrace();
}
// 上传文件
notice.setAttch(path_ + "uploaddir\\" + uploadFileName);
notice.setAttachmentname(uploadFileName);
}
inoticeService.save(notice);
inoticeService.savePd(notice.getS_date(), notice.getDescription());
return "save";
} catch (Exception e) {
e.printStackTrace();
this.addErrors(e.getMessage(), e);
return ERROR;
}
}
上传附件 multipart/form-data

------解决方案--------------------
你的应用部署是以WAR包方式部署的吧?
WAR包方式无法支持ServletContext类的getRealPath()方法,也就是getServletContext().getRealPath("/")得到的值始终为NULL。解决方案是使用ServletContext的getResource或getResourceAsStream获取WEB应用的文件路径
可以参考下http://blog.csdn.net/gl74gs48/article/details/8264300
------解决方案--------------------
enctype="multipart/form-data有这句,request.getXX就不能用了,这是一个bug