[英]How to map a servlet filter on /* in Jetty?
I have a servlet filter which I want to map to http://127.0.0.1:8888/ in Jetty. 我有一个servlet过滤器,我想映射到Jetty中的http://127.0.0.1:8888/ 。 I have put a servlet filter mapping with url pattern /*
. 我已经将servlet过滤器映射映射为url模式/*
。 However, the filter is not called. 但是,不调用过滤器。 I also tried with /
mapping. 我也尝试了/
映射。 It does not work either. 它也不起作用。 How is this caused and how can I solve it? 这是怎么引起的,我该如何解决?
If you name your war root.war
it will be deployed to the root / context. 如果您将war root.war
,它将被部署到root /上下文中。
http://wiki.eclipse.org/Jetty/Howto/Deploy_Web_Applications http://wiki.eclipse.org/Jetty/Howto/Deploy_Web_Applications
You can redirect requests from "/" to "/urlToRedirect" and handle "/urlToRedirect" by special servlet. 您可以将请求从“ /”重定向到“ / urlToRedirect”,并通过特殊的servlet处理“ / urlToRedirect”。 Like in example: 例如:
public static void main(String[] args) throws Exception {
Servlet frontend = new Frontend();
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(frontend), "/index");
context.addServlet(new ServletHolder(frontend), "/auth");
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(false);
resource_handler.setResourceBase("static");
RewriteHandler rewriteHandler = new RewriteHandler();
rewriteHandler.setRewriteRequestURI(true);
rewriteHandler.setRewritePathInfo(true);
rewriteHandler.setOriginalPathAttribute("requestedPath");
RedirectRegexRule rule = new RedirectRegexRule();
rule.setRegex("/");
rule.setReplacement("/index");
rewriteHandler.addRule(rule);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{rewriteHandler, resource_handler, context});
server.setHandler(handlers);
server.start();
server.join();
}
Jetty网络应用部署文档提到wep应用可以打包为root.war
以具有根上下文/
Each application in jetty is deployed to its context - meaning it have some part after the slash - ie http://127.0.0.1:8888/context/ - your servlet mapping is realitve to the last slash - not the one before context Jetty中的每个应用程序都已部署到其上下文中-意味着它在斜杠后有一部分-即http://127.0.0.1:8888/context/-您的servlet映射是到最后一个斜杠的,而不是上下文前的斜杠
As mentioned in the other answers you must deploy the application as root.war to overcome this. 如其他答案所述,您必须将应用程序部署为root.war才能克服此问题。
(可选)您可以在$JETTY_HOME/webapps
下创建一个名为root
的目录,并将您的Web应用程序内容复制到$JETTY_HOME/webapps/root
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.