wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Identify context path + servlet path+ path info for given URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Identify context path + servlet path+ path info for given URL" Watch "Identify context path + servlet path+ path info for given URL" New topic
Author

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

Srikanth shetty Nukala
Greenhorn

Joined: Apr 07, 2006
Posts: 20
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.


Regards,<br />SCJA<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD or SCEA - coming soon!
Connie Ky Leung
Ranch Hand

Joined: Jan 29, 2006
Posts: 42
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.


SCJP 1.4 - 91%, SCWCD - 97%, SCJP 5.0 - 83%, SCJP 6.0, OCEJWCD - 80%
Gaurav Gambhir
Ranch Hand

Joined: Mar 04, 2006
Posts: 254
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

Joined: Jan 13, 2006
Posts: 136
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

Joined: Mar 27, 2006
Posts: 245
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 ?


Vikrant Pandit
singh santosh
Ranch Hand

Joined: Jan 13, 2006
Posts: 136
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

Joined: Apr 07, 2006
Posts: 20
Thanks that was very informative.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Identify context path + servlet path+ path info for given URL