• 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

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks that was very informative.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic