0

I have a web application using embedded tomcat/jasper, configured in-code as such:

public class Main {
    public static void main(String[] args) throws Exception {

        String webappDirLocation = "src/main/webapp/";
        Tomcat tomcat = new Tomcat();

        // The port that we should run on can be set into an environment variable
        // Look for that variable and default to 8080 if it isn't there.
        String webPort = System.getenv("PORT");
        if (webPort == null || webPort.isEmpty()) {
            webPort = "8080";
        }

        tomcat.setPort(Integer.valueOf(webPort));

        StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
        File additionWebInfClasses = new File("target/classes");
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(
                new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
        ctx.setResources(resources);
        ctx.setDelegate(true);


        tomcat.start();
        tomcat.getServer().await();
    }
}

I have some legacy JSP taglibs that need to have JSP pooling turned off in Jasper.

https://tomcat.apache.org/tomcat-8.5-doc/jasper-howto.html

The web.xml file does not set up the jasper servlet (only custom servlets that handle request mapping), and all JSPs/taglibs run fine (other than the pooling issue). How can I set the "enablePooling" jasper setting to false using the "main" function I have above, utilizing embedded Tomcat?

LetsBeFrank
  • 774
  • 11
  • 31

1 Answers1

0

How about this?

Wrapper jspServlet = context.createWrapper();
jspServlet.setName("jsp");
jspServlet.setServletClass("org.apache.jasper.servlet.JspServlet");
jspServlet.addInitParameter("enablePooling", "false");
...
ctx.addChild(jspServlet);
Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49