jsr369-experts@servlet-spec.java.net

[jsr369-experts] [SERVLET_SPEC-16] Proposal: Programmatic equivalent to jsp-file

From: Edward Burns <edward.burns_at_oracle.com>
Date: Mon, 30 Jan 2017 10:49:12 -0800

Hello Volunteeers,

ACTION: Please respond by close of business GMT-0800 Thursday otherwise
I'll specify and implement the above proposal.

Consider the existing API for programmatically adding a Servlet:

@WebListener()
public class NewServletListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {

        final ServletContext servletContext = sce.getServletContext();
        final ServletRegistration.Dynamic dynamic = servletContext.addServlet("newjsp",
                [String, Class or Servlet]);
        dynamic.addMapping("/newjsp");

    }

}

Consider the existing API for declaring a Servlet is actually a JSP
page:
    
    <servlet>
        <servlet-name>newjsp2</servlet-name>
        <jsp-file>/newjsp2.jsp</jsp-file>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>newjsp2</servlet-name>
        <url-pattern>/newjsp2</url-pattern>
    </servlet-mapping>

SERVLET_SPEC-16 seeks to allow programmatically declaring a Servlet is a
JCP. I propose the following API for this operation:

@WebListener()
public class NewServletListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {

        final ServletContext servletContext = sce.getServletContext();
        final ServletRegistration.Dynamic dynamic = servletContext.addServlet("newjsp",
                ServletContext.JSP_SERVLET_CLASS_REFERENCE);
        dynamic.setJspFile("/newjsp.jsp");
        dynamic.addMapping("/newjsp");

    }

}

This implies a new method on ServletRegistration.Dynamic:
setJspFile(String).

It also implies a new constant on ServletContext:
JSP_SERVLET_CLASS_REFERENCE.

As far as I know, and I could be wrong about this, but the existing API
does require the use of one of the addServlet() variants on
ServletContext. Given that assumption, neither the Class nor the Servlet
variants are appropriate for a Servlet that is a JSP page. That leaves
String. We have a private constant that is used internally for such
things, but that is implementation specific. So, I judged the easiest
and most minimal impact would be achieved by introducing a new constant
whose meaning is as I've documented in the patch attached to the JIRA.

ACTION: Please respond by close of business GMT-0800 Thursday otherwise
I'll specify and implement the above proposal.

Thanks,

Ed

-- 
| edward.burns_at_oracle.com | office: +1 407 458 0017
| 26 business days until planned start of JSF 2.3 Final Approval Ballot
| 16 business days until DevNexus 2017
| 41 business days until JavaLand 2017