• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mapping Servlet to just the Context Root?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic