简体   繁体   English

在 tomcat-embed-jasper 中禁用 JSP 池

[英]Disable JSP pooling in tomcat-embed-jasper

I have a web application using embedded tomcat/jasper, configured in-code as such:我有一个使用嵌入式 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();
    }
}

I have some legacy JSP taglibs that need to have JSP pooling turned off in Jasper.我有一些遗留的 JSP 标记库需要在 Jasper 中关闭 JSP 池。

https://tomcat.apache.org/tomcat-8.5-doc/jasper-howto.html 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). web.xml 文件不设置 jasper servlet(仅处理请求映射的自定义 servlet),并且所有 JSP/taglib 运行良好(池问题除外)。 How can I set the "enablePooling" jasper setting to false using the "main" function I have above, utilizing embedded Tomcat?如何使用我上面的“main”函数,利用嵌入式 Tomcat 将“enablePooling”jasper 设置设置为 false?

How about this?这个怎么样?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM