• 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

URL mapping confusion

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
servlet name path pattern
controler *.do
data /data/*


I am getting confused on , what will be the output when browser has a URL "/data/command.do" . Does it look the order of <servlet-mapping> in DD to judge the Servlet name to be called? Can any body please help me in clearing this confusion?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ani jadhao wrote:
Does it look the order of <servlet-mapping> in DD to judge the Servlet name to be called? Can any body please help me in clearing this confusion?



First container will try to find the exact match of the url, if that failed then the container will try to match the longest path-prefix.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vijitha is correct. The container will try to find a match of the URL in the request not based on the declaration order, but according on the following order:

1) Exact match of the URL (e.g. /data/command.do)
2) longest path prefix (e.g. /data/*)
3) Extension mapping (e.g. *.do)
4) Default servlet (e.g. /)
 
ani jadhao
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is mean by longest possible path from requet URI?


For e.g. /autobank/accountservlet/balance .

Not for context , container finds the longest path possibly.
does it mean . container try to find
-/autobank/accountservlet/balance
- /autobank/accountservlet and then
-/autobank

Same logic applies to servlet path ?/??
 
ani jadhao
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it .The confusion came when I was comparing the same with filter chain mapping in web.xml. .

Somple conclusion I came on :
For Servlets , in web.xml, there is no kind a rule for order of <servlet-mapping>, container will recurse through the requesr URI , from left right , finding the longest posible match.
If found stop further search and calls the servlet , of it will cut down left part seperated by / and search the rest recursively.

The same will continue till it finds a match , If it doesnt , it will directed to default servlet, if default servlet doesnt exisis , an error will be shown .

In case of filter, mapping is done with every filter URL , but in the order declared in web.xml to create a chain of filters and calls them accordingly.

Please correct me if I have mistated some where.
 
Matteo Palmieri
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ani,

is it true that for filters the definition order in the DD is relevant, but make sure you know
that the following rules will be applied by the servlet container in the specified order:
1) Apply all filters with url-pattern matching the request (in the same order they are defined)
2) Apply all filters with servlet-name matching the request (in the same order they are defined)

Example:


The order will be: Filter1, Filter3, Filter2, Filter4, that is Filter2 and Filter4 will be coming after because they match a servlet-name

Regards, Matteo
 
reply
    Bookmark Topic Watch Topic
  • New Topic