做单文件上传开发过程
1 jsp页面from表单enctype写成multipart/form-data的值
<form action="${pageContext.request.contextPath }/uplAction" method="post" enctype="multipart/form-data">
<input type="file" name="haha">
<input type="submit" value="上传">
</form>
2 web.xml配struts的过滤器
3 陪struts.xml配置文件
4 编写action类,此类基础actionSupport,提供jsp页面上传文件的haha值,hahaContentType,hahaFileName,和其set方法
当做上传动作时,struts的一个org.apache.struts2.interceptor.FileUploadInterceptor拦截器,他默认拦截2m以下的文件,当上传的文件太大时会发生以下异常,
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException
默认的配置在“struts2-core-2.0.11.1.jar\org\apache\struts\ default.properties”中的struts.multipart.maxSize=2097152语句,如果想改大的话,就重新设定它,有两种方法:
其解决办法如下:
一种是重写:struts.properties文件。
二是在struts.xml中加入常量来改变它如“ Java代码
<constant name="struts.multipart.maxSize" value="10000000" />