How to avoid request set ASYNC_SUPPORTED=true to enable async servlet 3.0 processing on Tomcat 7?

点点圈 提交于 2019-11-27 20:44:17
kschneid

A couple of things to check first:

Make sure any filters that operate on the request also support async (as addressed in one of the answers to the question you referenced).

Make sure you're using a Servlet 3.0 web.xml - for example:

<web-app 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"
         version="3.0"
         metadata-complete="true">

Try upgrading.

  • Bug 53623 fixed in 7.0.30.
  • "Enable remaining valves for Servlet 3 asynchronous processing support." (fixed in 7.0.16)

Check the Tomcat 7 ChangeLog for complete details.

Also, if you want to use async, then you'll need to make sure that all of the filters and valves in the chain (as well as the servlet, of course) all support async. This is likely the problem in the original question, as well as with your case, here.

I found that org.apache.catalina.ASYNC_SUPPORTED=true is only needed when you from one normal-servlet/jsp (internally) forward to an async-servlet! Example: In my index.jsp, I embed <jsp:forward page="/path/AsyncServlet" /> I promise the AsyncServlet works fine on both Tomcat7 and Glassfish3, when I directly trigger it from browser! However when I trigger it by index.jsp: Tomcat7 reports 500 for "Not supported" Glassfish3 reports 500 for "Request is within the scope of a filter or servlet that does not support asynchronous operations" If I embed <% request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true); %> before <jsp:forward> in index.jsp, Tomcat7 goes OK, but Glassfish3 still is BAD! So I found a solution for both Tomcat7 and Glassfish3 (without SYNC_SUPPORTED!): Just EXACTLY attach followings in web.xml:

<servlet>
    <servlet-name>indexPage</servlet-name>
    <jsp-file>/index.jsp</jsp-file>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>indexPage</servlet-name>
    <url-pattern>/index.jsp</url-pattern>
  </servlet-mapping>

Conclusion (for me): You can NOT forward from a normal-servlet/jsp/filter to an async-one! Since the async-request feature MUST be preset! So the common solution for a servlet/jsp/filter which needs to forward to an async-servlet is: Use <servlet>/<async-supported>true or @WebServlet(asyncSupported = true) for a pre-processed servlet; Use <servlet>/<async-supported>true for a pre-processed jsp Use <filter>/<async-supported>true or @WebFilter(asyncSupported = true) for a pre-processed filter; Hope this may help a little bit!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!