Struts中文件上传时的空指针异常处理以及获取不到上传文件相关属性

来源:互联网 发布:中国淘宝第一村大集镇 编辑:程序博客网 时间:2024/05/18 00:36
<span style="font-size:14px;"><span style="white-space:pre"></span>private File file;//文件private String fileFileName;//文件名private String fileContentType;//文件MIME类型</span>

1.第一步确定自己起的名字要和G:\higher class\code\01_struts_action\WebContent\WEB-INF\lib\commons-fileupload-1.3.2.jar该jar包支持的名字一致

<span style="font-size:14px;"><form action="${pageContext.request.contextPath }/upload/upload_uploadFile"method="post" enctype="multipart/form-data"><table border="1" width="50%"><tr><td>选择文件:</td><td><input type="file" name="file"/></td></tr><tr><td><input type="submit" value="提交"/></td></tr></table></form></span>

2.确定自己的jsp页面form表单的method为post(因为是上传文件,不设置的话会默认是get),一定记住设置属性enctype="mutipart/form-data"(以二进制文件进行传输)。


2 0
原创粉丝点击