我在为 Web 应用程序设置处理程序时遇到问题,我想要的是:通过 withHTTPServlet和doGet方法处理一些请求doPost(如何从这些方法中加载 JSP 页面?)并且还能够加载静态内容(html、JS、CSS)。
我现在的设置方式,只能选择其中之一,无法同时使用。
我会解释:
Server server = new Server(5000);
// This is the resource handler for JS & CSS
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(".");
resourceHandler.setDirectoriesListed(false);
// This is the context handler for the HTTPServlet
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(new ServletHolder(new Main()),"/*");
// this is the Handler list for both handlers
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { context ,resourceHandler});
/*
If I add them in this …Run Code Online (Sandbox Code Playgroud)