I adore with the built-in Jetty, and I wonder why my filter only intercepts /hi, and not any other incoming request. Here is my example:
Without a filter:
localhost:8080/hi
=> "Hello"
localhost:8080/foo
=> 404
With filter:
localhost:8080/hi
=> "Hello from filter"
localhost:8080/foo
=> 404
I expect the last 404 to return "Hello from filter". What am I missing?
Server server=new Server(8080);
ServletContextHandler context=
new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addFilter(DispatchFilter.class,"/*",1);
context.addServlet(HelloServlet.class,"/hi");
server.setHandler(context);
server.start();
server.join();
To clarify, my example is just a simplified view of what I want to do. My intention is to DispatchFilterintercept every request. If certain criteria are not met, then it should move on, otherwise return something obtained from the request path.
source
share