내 웹 응용 프로그램에 대한 핸들러 설정에 문제가 있습니다. 원하는 것은 doGet 및 doPost 메소드로 HTTPServlet에서 처리하는 요청을 처리하는 것입니다. (이 메소드 내에서 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 order, all requests will be handled by the "context" and no static resource is loaded
If I invert the order, the index page page is loaded by the resource handler, which means, If I activate directory listings, it gives me a list of all directories, otherwise it's just a blank page
I tried working with a WebAppContext to load JSP pages but I still had some problems with which handler should handle which requests
*/
server.setHandler(handlerList);
server.start();
server.join();
감사합니다
는 는** 편집 : ** 내가 가진 문제는 내 HTTP 서블릿은 다음과 같은 방식으로 동작한다는 것입니다
는 : 는 모든 요청을 처리합니다 리소스 핸들러에는 아무 것도 남기지 않으므로 스크립트가 .js 스크립트를 요청하면 대신 빈 html 페이지를 반환합니다. 메인 서블릿없이 루트 핸들러를 사용하는 경우, 그것은 모든 정적 컨텐츠 및 JSP 페이지를로드하지 않지만, 주요 서블릿을 추가 할 때, 그것은 더 이상 정적 콘텐츠를로드이 예에서
WebAppContext root = new WebAppContext();
root.setParentLoaderPriority(true);
root.setContextPath("/");
root.setResourceBase(".");
root.setWelcomeFiles(new String[] {"test.jsp"});
root.addServlet(new ServletHolder(new Main()),"/*");
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { root });
: 여기 은 예입니다 빈 html 페이지로 정적 컨텐츠에 대한 모든 요청에 응답합니다.
덕분에, 정적 컨텐츠와 서블릿의 내용이 지금 동시에 작업하고 있지만, 로딩 JSP 페이지를로드하는 것은 아니다 일하는 (나는 그 빈 페이지를 얻고있다). HTTPServlet JSP 페이지가 제대로로드되지 않았다는 것을주의하십시오. –
JSP가 지원되는 Embedded Jetty는 훨씬 더 많은 설정이 필요합니다. 공식 예제 (https://github.com/jetty-project/embedded-jetty-jsp) –
고마워, 이미 거기있어. 나는 이렇게하고 있고 일하고있다. 연습이 얼마나 나쁜가? response.sendRedirect ("jsp/index.jsp"); –