jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.86k stars 1.91k forks source link

How config async support in jsp tag? #1112

Closed liyiorg closed 7 years ago

liyiorg commented 7 years ago

Hi, I want use async request in JSP tag. Jetty version:9.2.19.v20160908

Example

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class TestJspTag extends TagSupport{

    @Override
    public int doStartTag() throws JspException {
        //jetty output false
        System.out.println(pageContext.getRequest().isAsyncSupported());

        //tomcat set request attribute "org.apache.catalina.ASYNC_SUPPORTED" value true,
        //output true

        /*
        pageContext.getRequest().setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
        System.out.println(pageContext.getRequest().isAsyncSupported());
        */

        return SKIP_BODY;
    }
}

How config output 'true' in Jetty?

janbartel commented 7 years ago

@liyiorg have you tried adding

<async-supported>true</async-supported>

to the definition of the JettyJspServlet inside etc/webdefault.xml? Don't forget if you edit that file that you need to apply it to your context. In xml that would be:

<Set name="defaultsDescriptor">/path/to/your/special/webdefault.xml</Set>

or in code:

webAppContext.setDefaultsDescriptor("/path/to/your/special/webdefault.xml");

I tested the above, and checked the value of request.isAsyncSupported() inside a jsp, and it was true.

Let me know if this works for you.

liyiorg commented 7 years ago

@janbartel Thanks! definition JettyJspServlet to web.xml,It's works OK!

<servlet id="jsp">
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.eclipse.jetty.jsp.JettyJspServlet</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>logVerbosityLevel</param-name>
            <param-value>DEBUG</param-value>
        </init-param>
        <init-param>
            <param-name>fork</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>xpoweredBy</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>compilerTargetVM</param-name>
            <param-value>1.7</param-value>
        </init-param>
        <init-param>
            <param-name>compilerSourceVM</param-name>
            <param-value>1.7</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.jspf</url-pattern>
        <url-pattern>*.jspx</url-pattern>
        <url-pattern>*.xsp</url-pattern>
        <url-pattern>*.JSP</url-pattern>
        <url-pattern>*.JSPF</url-pattern>
        <url-pattern>*.JSPX</url-pattern>
        <url-pattern>*.XSP</url-pattern>
    </servlet-mapping>
janbartel commented 7 years ago

Cool.

Assigning to Chris for some documentation: we might make mention of how to configure the jsp servlet in order to support async operations in jsps/taglibs.

sbordet commented 7 years ago

@janbartel should we not change our webdefault.xml to default to async-supported=true ? Nowadays it's perhaps a better default than few years ago.

janbartel commented 7 years ago

@sbordet I guess we could. I am hesitating because normally one would expect async-supported=true to apply to the servlet it is declared on: however in this case, it is really applying to the servlets that are generated by the JspServlet, not the JspServlet itself. Which seems a bit weird.

sbordet commented 7 years ago

@janbartel your call then to whether change th default or improve documentation.

janbartel commented 7 years ago

@liyiorg note that you could also have just put the following lines into your web.xml, instead of changing webdefault.xml:

  <servlet id="jsp">
    <servlet-name>jsp</servlet-name>
    <async-supported>true</async-supported>
  </servlet>

I think we'll just document this for now.

liyiorg commented 7 years ago

@janbartel Thank you very much! It also applies to Tomcat. I'm writing a JSP big page project. https://github.com/liyiorg/viewblock

Is there any good advice for me,Dear experts!