SpringMVC 启用异步支持,使用异步方法遇到的问题
Async support must be enabled on a servlet and for all filters involved in async request processing.
This is done in Java code using the Servlet API or by adding
"<async-supported>true</async-supported>"
to servlet and filter declarations in web.xml.
解决方案:
在web.xml里面添加支持:
<!-- servlet 配置上异步支持 -->
<async-supported>true</async-supported>
<!-- filter 配置上异步支持 -->
<dispatcher>ASYNC</dispatcher>
例:
<!-- 解决post乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<!-- 配置上异步支持 -->
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
<!-- springmvc前端控制器 -->
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<!-- 配置上异步支持 -->
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>