开发者

Jetty embedded: JSP and Servlets together?

I have an application with embedded Jetty 6.1.26. Servlet 2.5. Below is my server configuration.

The problem is, that when I try to have JSPs and Servlets together, it does not work. I eithe开发者_如何学运维r have one or the other working, based on whether I have server.addHandler() or server.setHandler() in the code below.

By "does not work" I mean that Jetty returns 404, but otherwise it looks fine, even Jetty log shows the configuration went fine - see http://pastebin.com/PzbEx0qc (that was with addHandler(), JSP was not working).

The URLS requested are

http://localhost:17283/jars?mvnPath=... and

http://localhost:17283/jsp/index.jsp .

Thanks, Ondra

Server server = new Server( PORT );
Context ctx = new Context( server, "/", Context.NO_SECURITY | Context.SESSIONS );


final String WEBAPP_RESOURCES_PATH = "org/jboss/qa/mavenhoe/web/jsp";
final String JSP_CONTEXT_PATH = "/jsp";

// For localhost:port/jsp/index.html and whatever else is in the directory...
final URL warUrl = this.getClass().getClassLoader().getResource(WEBAPP_RESOURCES_PATH);
final String warUrlString = warUrl.toExternalForm();
    WebAppContext webAppContext = new WebAppContext(warUrlString, JSP_CONTEXT_PATH);
webAppContext.setAttribute("jarIndex", jarIndex);
server.addHandler( webAppContext );


// .jar's download.
final ServletHolder mavenhoeSH = new ServletHolder(new JarFinderServlet(this.jarIndex));
ctx.addServlet( mavenhoeSH, "/jars" );


final ServletHolder shutdownSH = new ServletHolder(new JettyShutdownServlet( server ));
shutdownSH.checkServletType();
ctx.addServlet( shutdownSH, "/shutdown" );


Each path component should be handled by its own context and make sure you use ContextHandlerCollection for multiple contexts.

ContextHandlerCollection contexts = new ContextHandlerCollection();

contexts.setHandlers(new Handler[] { jspContext, servletContext });

server.setHandler(contexts);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜