Answer the question
In order to leave comments, you need to log in
Jetty does not return html. Where is the crooked hand?
I'm using jetty and I'm facing the fact that it returns 404 to me
apiServer = new Server();
ServerConnector connector = new ServerConnector(apiServer);
connector.setPort(Constants.PORT);
connector.setHost(Constants.HOST);
apiServer.addConnector(connector);
HandlerList apiHandlers = new HandlerList();
//add page with visualisator;
ServletContextHandler apiHandler = new ServletContextHandler();
ServletHolder defaultServletHolder = new ServletHolder(new DefaultServlet());
defaultServletHolder.setInitParameter("resourceBase", "ui");
apiHandler.addServlet(defaultServletHolder, "/*");
apiHandler.setWelcomeFiles(new String[]{"tester.html"});
apiHandlers.addHandler(apiHandler);
apiHandlers.addHandler(new DefaultHandler());
apiServer.setHandler(apiHandlers);
try {
apiServer.start();
} catch (Exception e) {
e.printStackTrace();
}
ClassLoader.getSystemResource("ui/tester.html")
Answer the question
In order to leave comments, you need to log in
Try like this
public static void main(String[] args) throws Exception{
DefaultServlet defaultServlet = new DefaultServlett();
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(defaultServlet ),"/");
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase("ui");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{resourceHandler, context});
Server server = new Server(Constants.PORT);
server.setHandler(handlers);
server.start();
server.join();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question