• 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

servlet-mapping / url-pattern: / vs /*

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. What is the semantic difference between / and /* in url-pattern of servlet-mapping? Is it any different?
 
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is in the servlet spec:

quote:
SRV.11.2 Specification of Mappings

In theWeb application deployment descriptor, the following syntax is used to define mappings:

* A string beginning with a / character and ending with a /* suffix is used for path mapping.
* A string beginning with a *. prefix is used as an extension mapping.
* A string containing only the / character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
* All other strings are used for exact matches only.



The pattern /* will force everything through your servlet.
The pattern / will make your servlet the default servlet for the app, meaning it will pick up every pattern that doesn't have another exact match.

Regards
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your answer.
I've just downloaded the specs and will read it ;-)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After getting this wrong like 2 dozen times over the last ten years, I want to say this post is probably the best answer *except* that the spec has one other provision that is relevant. JSPs are implicitly mapped to the "*.jsp" mapping. So, if you use the mapping that puts everything through your servlet (/*), you basically can't use JSPs (cuz any time you forward or redirect to a JSP, the request is going to boomerang back to your servlet).
 
Sheriff
Posts: 67747
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
This also applies to other resources such as images, stylesheets and scripts. It's rarely useful to map /*.

Also, dexter morgan, please use real words when posting to the forums and avoid fake words such as "cuz". Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic