(轉)使用Servlet3.0新特性asyncSupported=true時拋異常java.lang.IllegalStateException: Not support...


http://www.tuicool.com/articles/zYfmme

最近在運用Servlet3.0新特性:異步處理功能的時候出現以下了2個問題:

運行時會拋出以下兩種異常:

一月 19, 2014 3:07:07 下午 org.apache.catalina.core.StandardWrapperValve invoke 嚴重: Servlet.service() for servlet [servletTest.AsyncServlet] in context with path [/idea] threw exception java.lang.IllegalStateException: Not supported.
一月 19, 2014 2:42:01 下午 org.apache.catalina.core.ApplicationContext log

經過反復排查,終於查出了問題原因,不多說,直接上結論:

1.使用asyncSupported=true必須運用tomcat7+JDK6以上版本。

2.必須在一個請求涉及的所有Servlet及Filter中都聲明asyncSupported=true。

簡單地說:

我寫了一個AsyncServlet.java(extends HttpServlet)中聲明了asyncSupported=true,

但是該請求還同時會觸發另外3個Filter,所以這3個Filter中也 必須聲明asyncSupported=true ,

這就是這個使用asyncSupported這個屬性的關鍵。

 

 

============================================================

http://www.cnblogs.com/yangzhilong/p/3725128.html

在spring mvc3.2及以上版本增加了對請求的異步處理,是在servlet3的基礎上進行封裝的。

1、修改web.xml

復制代碼
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
...
</web-app>
復制代碼

1.1、聲明version="3.0",聲明web-app_3_0.xsd

1.2、為servlet或者filter設置啟用異步支持:<async-supported>true</async-supported>,修改WEB應用的web.xml

復制代碼
<!-- spring mvc -->
<servlet>
<servlet-name>SpringMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>...</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
復制代碼


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM