我有一个使用嵌入式tomcat / jasper的Web应用程序,其代码配置如下:

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();
    }
}


我有一些旧的JSP taglib,需要在Jasper中关闭JSP池。

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

web.xml文件未设置jasper servlet(仅处理请求映射的定制servlet),并且所有JSP / taglib运行正常(除了池问题)。如何使用嵌入式Tomcat使用上面的“ main”功能将“ enablePooling” jasper设置设置为false?

最佳答案

这个怎么样?

Wrapper jspServlet = context.createWrapper();
jspServlet.setName("jsp");
jspServlet.setServletClass("org.apache.jasper.servlet.JspServlet");
jspServlet.addInitParameter("enablePooling", "false");
...
ctx.addChild(jspServlet);

关于java - 在tomcat-embed-jasper中禁用JSP池,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59058181/

10-12 01:45