This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Identify context path + servlet path+ path info for given URL

 
Srikanth shetty Nukala
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi found this question in several mocks,

so need clarification.

URL is : http://server:8080/AppName/Abc/Servlet?param1=value1¶m2=value2

so what is the context path, servlet path and path info for these URL's?

Thanks.
 
Connie Ky Leung
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srikanth shetty Nukala:
Hi found this question in several mocks,

so need clarification.

URL is : http://server:8080/AppName/Abc/Servlet?param1=value1¶m2=value2

so what is the context path, servlet path and path info for these URL's?

Thanks.




Context path is AppName

If directory match is performed against the servlet, then servlet path is ABC and path info is Servlet.

If exact match is performed against the servlet, then servlet path is ABC/Servlet and path info is null.

Please correct me if I am wrong.
 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quote
"URL is : http://server:8080/AppName/Abc/Servlet?param1=value1�m2=value2
so what is the context path, servlet path and path info for these URL's?"


Request URI=context path + servlet path + path info+query string

Request_URI = Context_Path [1] + Servlet_Path [2] + Path_Info [3] + Query_String [4]
/catalog[2]/product[3]?mode=view[4]]http://server.com/my_app_context[1]/catalog[2]/product[3]?mode=view[4]

Context Path/AppName

Servlet Path /ABC

Path Info/Servlet

Query String param1=value1&m2=value2
 
singh santosh
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi gaurav,
As mentioned by Connie the value of Servlet path and path info depends on the <url-pattern> subelement of <servlet-mapping> element so

i think ur answer is partially correct(suaitable when the url-pattern defines a exact path match) but Connie has correctly mentioned both the scenario when the url pattern defines a)directory matching(eg. /sample/*) b)exact path matching(eg /sample/test)

So the answer of the question really depends on how the url-pattern is configured in web.xml

regards
-santosh
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santosh

I have a doubt regarding this .
Suppose I have a webapps directory somewhat like this

webapps
|_ ROOT
|_ MyApp

There is servlet mapping in ROOT app where there is a mapping like this /MyApp/servlet/xyz

and in MyApp ap we have a servlet mapping /servlet/xyz .

Servlet from which application is picked up ?
 
singh santosh
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi vivek,

I have a doubt regarding this .
Suppose I have a webapps directory somewhat like this

webapps
|_ ROOT
|_ MyApp

There is servlet mapping in ROOT app where there is a mapping like this /MyApp/servlet/xyz

and in MyApp ap we have a servlet mapping /servlet/xyz .

Servlet from which application is picked up ?


Its very important to know how container picks a servlet from which web app .(means how it identify the correct web app and then correct servlet)

Since the request uri consist of three main parts
Context Path- this helps container to choose the correct web app
ServletPath-this helps container to identify correct servlet into the from the requested web app.
PathInfo-in case of directory match

So if the request uri is
http://server.com/MyApp/servlet/xyz ,the container will first look for a web app named MyApp if it exists then it will look for the resource(here servlet) mapped to /servlet/xyz.

In case if there is no web app named MyApp then it (Tomcat)will look into the default web app (ROOT) for the servlet mapped to the uri /MyApp/servlet/xyz and proceed acc to that.
I have also tested this on my Tomcat

Correct me i am wrong..

regards
-santosh
[ May 02, 2006: Message edited by: singh santosh ]
 
Srikanth shetty Nukala
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that was very informative.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic