我不明白我怎么能改写用于jetty 6的jetty 6的代码:
import org.mortbay.jetty.*; import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.webapp.WebAppContext; public class ApplLauncher { public static void main(String[] args) { Server server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(8080); server.addConnector(connector); WebAppContext root = new WebAppContext("C:\\Users\\OZKA\\IdeaProjects\\projectname\\projectname\\web","/"); root.setWelcomeFiles(new String[]{"index.html"}); //root.addServlet(new ServletHolder(new TestServlet()),"/test"); server.setHandlers(new Handler[]{root}); try { server.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
上面的代码工作正常,并响应web.xml中映射的web文件夹和servlet中的静态内容.这是我尝试使用嵌入式码头9:
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.Handler; public class ApplLauncher { public static void main(String[] args) { System.out.println("Hello from ScalaSbt Web Project"); Server server = new Server(8080); WebAppContext webapp = new WebAppContext("D:\\Dev\\Scala\\ScalaTestProject\\web\\","/"); ResourceHandler resource_handler = new ResourceHandler(); resource_handler.setWelcomeFiles(new String[]{ "index.html" }); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { resource_handler,webapp}); server.setHandler(handlers); try { server.start(); server.join(); } catch(Exception ex) { ex.printStackTrace(); } } }
服务器正在启动,但index.html请求抛出错误:
"java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z"
我试图在谷歌找到一个有效的例子,但没有发现任何有用的东西.官方样本和文档非常混乱,我不明白我如何使用embeded jetty版本9.