简体   繁体   English

有没有办法在嵌入式码头中以编程方式设置context-params?

[英]Is there a way to set context-params programmatically in embedded jetty?

Looking at the following example of an embedded Jetty Example: http://musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html 查看嵌入式Jetty示例的以下示例: http//musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html

The following code sample is given (below. 下面给出了代码示例(如下)。

The author then goes on an gives an example of referring to context params in a web.xml file. 然后,作者继续举例说明在web.xml文件中引用上下文参数。 eg 例如

...
<context-param>
  <param-name>com.sun.faces.expressionFactory</param-name>
  <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
...

My question is - if I want to do everything in a Java class - is there a way to set context-params programmatically? 我的问题是 - 如果我想在Java类中做所有事情 - 有没有办法以编程方式设置context-params?

public class JettyRunner {

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

        Server server = new Server();

        Connector connector = new SelectChannelConnector();
        connector.setPort(8080);
        connector.setHost("127.0.0.1");
        server.addConnector(connector);

        WebAppContext wac = new AliasEnhancedWebAppContext();
        wac.setContextPath("/myapp");
        wac.setBaseResource(
            new ResourceCollection(
                new String[] {"./src/main/webapp", "./target"}));
        wac.setResourceAlias("/WEB-INF/classes/", "/classes/");

        server.setHandler(wac);
        server.setStopAtShutdown(true);
        server.start();
        server.join();
    }
}

In your case 在你的情况下

wac.setInitParameter("com.sun.faces.expressionFactory",
                     "com.sun.el.ExpressionFactoryImpl")

will do. 会做。

    ServletContextHandler context = new ServletContextHandler(
            ServletContextHandler.SESSIONS);
    context.setContextPath("/");

above code should work for you. 上面的代码应该适合你。

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

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