This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

url-pattern for directory match

 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2168
57
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Saloon Keeper
Pie
Posts: 2168
57
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • 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
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Great answer. Thanks!
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic