序言
好久没有写博客了,今天是10.24号,属于程序员的节日,写一点以前遇到过的bug吧
遇到的问题
在使用maven创建web-app的时候,如果是用servelet3.0的文件上传需要配置一下文件
<multipart-config>
<!-- 上传文件的大小限制,-1表示无限大-->
<max-file-size>-1</max-file-size>
<!-- 一次表单提交中文件的大小限制,-1代表无限大 -->
<max-request-size>-1</max-request-size>
<!-- 多大的文件会被自动保存到硬盘上。0 代表所有 -->
<file-size-threshold>0</file-size-threshold>
</multipart-config>
会提示如下错误:
解决方法
因为是severlet3.0才有的,所以是因为WEB-app的版本过低,修改3.0及以上版本即可
修改web.xml头部为我使用4.0版本
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<multipart-config>
<!-- 上传文件的大小限制,比如下面表示 无限大 -->
<max-file-size>-1</max-file-size>
<!-- 一次表单提交中文件的大小限制,必须下面代表 无限大 -->
<max-request-size>-1</max-request-size>
<!-- 多大的文件会被自动保存到硬盘上。0 代表所有 -->
<file-size-threshold>0</file-size-threshold>
</multipart-config>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>