• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

url-pattern for directory match

 
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is based on HFSJ-2nd edition --> chapter 11 Web app deployment --> pg 619.

According to the book, if following is the url-pattern in the DD:
<servlet-mapping>
<servlet-name>SomeName</servlet-name>
<url-pattern>/fooStuff/*</url-pattern>
</servlet-mapping>


And the request is: http://locathost:8080/AppName/fooStuff

There would be a match in the above scenario.

However, doesn't the container interpret the fooStuff in the browser window as servlet name itself rather than any servlet under the directory fooStuff. In this case shouldn't the answer be 404 - page not found error?


[Edit: I think I posted this topic in the wrong forum. Could someone please move this to SCWCD certification forum (I cannot do it) - Thanks, Nidhi ]
 
Creator of Enthuware JWS+ V6
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nidhi,

However, doesn't the container interpret the fooStuff in the browser window as servlet name itself rather than any servlet under the directory fooStuff. In this case shouldn't the answer be 404 - page not found error?


I am not sure what you are trying to ask here.

The container finds a match on the directory pattern (/fooStuff matches with /fooStuff/*) and looks up which Servlet is mapped to that pattern. In this case the request will be directed to the Servlet with name SomeName (I am missing the <servlet> tag in your question)

Regards,
Frits
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fritz,

Thanks for the answer. I guess I was needlessly complicating it. Somehow I thought if the user enters www.example.com/fooStuff, it will NOT match a pattern of:
<url-pattern>/fooStuff/* </url-pattern>

(Since one is resource name & the second is directory), but I guess the container doesn't see it that way.

Please correct me if I am wrong.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(Since one is resource name & the second is directory), but I guess the container doesn't see it that way.



Well, there are two steps:
  • match to the web-application
  • match to the servlet


  • this is how the spec describes the match to the web-application:

    Upon receipt of a client request, the Web container determines the Web application to which to forward it. The Web application selected must have the the longest
    context path that matches the start of the request URL. The matched part of the URL is the context path when mapping to servlets.


    match to the servlet is described like this:

    The path used for mapping to a servlet is the request URL from the request object minus the context path and the path parameters.


    have a look at the picture:

    There must be a match on the contextPath, so in the request URL (http://localhost:8080/AppName/fooStuff ) there will be a match on http://localhost:8080/AppName, where AppName is the (context-root of the) web-application on your server.
    The remaining part ot the request URL (/foostuff) will be used to match against the url-patterns in your web.xml

    Be careful: /foostuff doesn't have to be a valid directory in your web-app! It is a virtual mapping.

    Does this clear your doubts?

    Regards,
    Frits
     
    Nidhi Sar
    Ranch Hand
    Posts: 252
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Great answer. Thanks!
     
    Trust God, but always tether your camel... to this tiny ad.
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic