jsr369-experts@servlet-spec.java.net

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

From: Shing Wai Chan <shing.wai.chan_at_oracle.com>
Date: Mon, 30 Jan 2017 12:58:21 -0800

Hi,

The following proposal does not require adding a new constant and is a one step process rather than two.
The idea is as follows:

When we add a servlet with a given class name, we have the following deployment descriptor:
<servlet>
       <servlet-name>myservlet</servlet-name>
       <servlet-class>MyServlet</servlet-class>
</servlet>

When we add a Jsp file, we have the following deployment descriptor:
<servlet>
       <servlet-name>myjsp</servlet-name>
       <jsp-file>/myjsp.jsp</jsp-file>
</servlet>

So, I suggest to add a new method to ServletContext, which is parallel to #addServlet as follows:

        ServletRegistration.Dynamic addJspFile(String jspName, String jspfile);


The following example illustrates the usage of the new API:
@WebListener()
public class NewServletListener implements ServletContextListener {

   @Override
   public void contextInitialized(ServletContextEvent sce) {

       final ServletContext servletContext = sce.getServletContext();
       final ServletRegistration.Dynamic dynamic = servletContext.addJspFile(“myjsp”, “/myjsp.jsp");
       dynamic.addMapping(“/newjsp”);
       ...
   }
}

Please let me know your comment.

Shing Wai Chan


> On Jan 30, 2017, at 10:49 AM, Edward Burns <edward.burns_at_oracle.com> wrote:
>
> 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