0

I use jetty in my spring app. After migrating from Jetty 8 to Jetty 9 (replacing SelectChannelConnector with ServerConnector) I'm left with 404 error code after navigating to main website address (spring security redirects me to /login) and log:

ERROR: PWC6117: File "/Users/jonny/projects/mypro/modules/backoffice/src/main/webapp/login" not found

it looks like jetty 9 doesn't honor web.xml file?, which is in my case

 <servlet>
    <servlet-name>login</servlet-name>
    <jsp-file>/login.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/login</url-pattern>
</servlet-mapping>

and my configuration of WebApp object is:

Server server = new Server(); 

WebAppContext webapp = new WebAppContext();
webapp.setContextPath(path);
webapp.setDescriptor("*src/main/webapp*/WEB-INF/web.xml");
webapp.setBaseResource(new ResourceCollection("*src/main/webapp*"));

HandlerList handlers = new HandlerList();
ServerConnector connector = new ServerConnector(server);
connector.setPort(*port*);
server.setConnectors(new Connector[]{connector});
handlers.addHandler(webApp);
server.setHandler(handlers);
server.start();
server.join();

I wish that /login served login.jsp, how to do that?

But the body of login.jsp is pure html and all I want is to serve it from /login context

Old: While searching for a hint I red:

but still don't know how to properly setup jetty with web.xml, any ideas?

Community
  • 1
  • 1
hanskoff
  • 182
  • 13
  • partial solution is to re-write login.jsp to login servlet and instead of `jsp-file` add `servlet-class` and that would work fine, but this is rather unpleasant and I wish to have jsp file – hanskoff Feb 11 '15 at 11:07

1 Answers1

0

If that code snippet represents how you are initializing your webapp, then you are missing a lot of JSP initialization steps.

There's an example project produced by the Jetty Project showing how to use JSP with embedded Jetty at

https://github.com/jetty-project/embedded-jetty-jsp

Pay attention to ...

  • The required ClassLoader type
  • The scratchDir declaration
  • The ServletContainerInitializer setup
  • The Jsp Servlet Holder and mappings
  • The InstanceManager

(just to name a few big ones)

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Hi again, I've changed a little my question, it's .jsp file only to serve html (in jetty8 it was ok). I've added mine resource handler but that completely doesn't work in case when I pack everything into fatjar ResourceHandler resHandler = new ResourceHandler(); resHandler.setResourceBase("/path/to/login.jsp"); ContextHandler ctx = new ContextHandler("/login"); ctx.setHandler(resHandler); – hanskoff Feb 11 '15 at 11:05
  • [Do not mix ResourceHandler and ServletContextHandler](http://stackoverflow.com/a/28419106/775715) (in fact, don't use ResourceHandler, at all, there is no advantage to using it over the DefaultServlet) – Joakim Erdfelt Feb 11 '15 at 12:45