Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Problema with DefaultServlet

I'm trying to embed Jetty in a Java application but I'm having the following problem.

I create my WebAppContext like this:
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");

Then I add my servlet twice like this:
ServletHolder jsServletHolder = new ServletHolder(new JSServlet());
webapp.addServlet(jsServletHolder, "*.do");
webapp.addServlet(jsServletHolder, "/");

Then I set the war at the webapp like this:
webapp.setWar("c:\temp");

But when I start my server:
server.start();

My WebAppContext auto configure itself and register the DefaultServlet to the path "/", so my servlet is never accessed through the root path. It redirects to the welcome files using the DefaultServlet.

I tried with no success setting the welcome files to something that doesn't exist like this:
webapp.setWelcomeFiles(new String[] {"This sure wont exist!"});

Is there some way to override this?
My web application doesn't have a web.xml because everything I need is being setup programmatically.

The resulting URL mapping is showing in the log like this:
          +-ServletHandler@196c1b0 started
             +-null
             +-[/*]/[]==0=>br.com.depasser.web.TimerFilter-12386568
             +-[*.do]=>br.com.depasser.jsservlet.JSServlet-10469011
             +-[/]=>br.com.depasser.jsservlet.JSServlet-10469011
             +-[/]=>default
             +-[*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp

My servlet is registered, but Jetty prefer his DefaultServlet, probably because it was registered after mine.

Registering my servlet after starting the server - and configuring the WebAppContext - works, but I don't think that should be the way to do it. Isn't there some other way of doing this?

Thanks,
Vinicius Isola
"Não podemos escolher as consequências, mas podemos escolher nossos atos."

Back to the top