[英]Possible to set context valve and realm programmatically using embedded jetty?
[英]Is there a way to set context-params programmatically in embedded jetty?
查看嵌入式Jetty示例的以下示例: http : //musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html
下面給出了代碼示例(如下)。
然后,作者繼續舉例說明在web.xml文件中引用上下文參數。 例如
...
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
...
我的問題是 - 如果我想在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();
}
}
在你的情況下
wac.setInitParameter("com.sun.faces.expressionFactory",
"com.sun.el.ExpressionFactoryImpl")
會做。
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
上面的代碼應該適合你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.