• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mapping Servlet to just the Context Root?

 
Andreas Schildbach
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

this looks like a very simple question, but it does not seem to be:

How can I map a Servlet to just the context root of my application, and nothing else?

For example, my application is mapped to

http://localhost/myapp/

I'd like to map my servlet to exactly

http://localhost/myapp/

but other resources like

http://localhost/myapp/img/image.gif

should still be handled by the default servlet.

Hint: <servlet-mapping>/</servlet-mapping> does not work, since this maps the default servlet as per spec.

Regards,

Andreas
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65533
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not try to map /*. This forum is full of people with bad scars from trying to do that.

What you might want to do is avoid mapping altogether and just set up your entry servlet as the "welcome file".
 
Andreas Schildbach
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is also a lot of issues with welcome files.

One particular problem is that some servlet containers do not implement them as forward rather than a redirect. So I'll end up with http://localhost/myapp/index.html in the address bar, which I absolutely do not want.

At the moment, I am experimenting with a custom Servlet Filter that forwards just "/" (and only that) to "/index.html".

Why did SUN not allow "/" as an exact match, and map that dreaded default servet with "*" or something similar?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!