2010-11-13 28 views
4

我有一個嵌入式Jetty 6.1.26的應用程序。 Servlet 2.5。 以下是我的服務器配置。Jetty嵌入式:將JSP和Servlets結合在一起?

問題是,當我嘗試將JSP和Servlet一起使用時,它不起作用。根據我在下面的代碼中是否有server.addHandler()server.setHandler(),我有一個或另一個工作。

由「不工作」我的意思是說,碼頭返回404,但否則它看起來很好,即使碼頭日誌顯示配置進展良好 - 見http://pastebin.com/PzbEx0qc(這是與addHandler(),JSP不工作)。

請求的URL是
http://localhost:17283/jars?mvnPath= ...和
http://localhost:17283/jsp/index.jsp

感謝, 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"); 

回答

0

每個路徑組件應該由它自己的範圍內進行處理,並確保您使用ContextHandlerCollection多個上下文。

ContextHandlerCollection contexts = new ContextHandlerCollection(); 

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

server.setHandler(contexts);