Struts2的文件上传注意点总结
1. 表单的enctype属性要设置为multipart/form-data
?
?
?2. 修改web.xml文件的配置
?
<!-- 定义Struts2的核心Filter --> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <!-- 定义Struts2核心Filter拦截的URL --> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 如果不加的话,会发生第一次上传取不到文件的情况 --> <filter> <filter-name>struts-cleanup</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>??
?