开发者

how to specify the contextPath

Hi I am using jetty servlets. I have the following structure.

war/web-inf/web.xml

war/classes/servlet.class (servlet I want to call)

war/*.html

Problem:

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.setContextPath("/");
    context.addServlet(new ServletHolder(new GreetingServiceImpl开发者_JS百科()), "/*");
    server.setHandler(context);
    try {
        server.start();

Can someone please tell me what is the contextPath supposed to be? I get http error 404: problem accesing ./

I need help. Thank you


That's the path in the URL after the domain where the webapplication should listen on.

If you set the context path to /foo, then the webapp will listen on http://example.com/foo and all pages/servlets will be available there in the /foo.

Here you're setting the context to /, which means that the webapp should listen on http://example.com. You're also creating a new servlet which intercepts on all requests (/*). So every request which goes through http://example.com would pass this servlet.

If you get a 404, then either the request URL is wrong, or the servlet failed to start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜