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");