user410911
user410911

Reputation: 65

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()), "/*");
    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

Upvotes: 0

Views: 3558

Answers (1)

BalusC
BalusC

Reputation: 1109532

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.

Upvotes: 1

Related Questions