File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes PathInfo RequestURI ServletPath and RequestPath Query 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 "PathInfo RequestURI ServletPath and RequestPath Query" Watch "PathInfo RequestURI ServletPath and RequestPath Query" New topic
Author

PathInfo RequestURI ServletPath and RequestPath Query

Aditi Kamra
Greenhorn

Joined: Aug 25, 2009
Posts: 7
Hi ,

I have my SCWCD exam this coming thursday .

Can somebody please clear explain me the terms ServletPath,RequestPath,PathInfo,RequestURI
and if possible with 1-2 examples , all these are really confusing , I read through the Servlet Specificationas well. but still not very clear.

Based on these concepts I have few questions as well ??
(1)If my browser request is : http://localhost8080/demo/testExamples/test/test1
If my servlet mapping is /test/*, then what would be the Servlet Path and PathInfo

(2) and another one from enthuware mock tests
If the servlet-mapping is /account/* and the requestURI is /myapp/account/*, then what would be the Servlet Path and PathInfo

Ans: /account is ServletPath, /* is PathInfo


Thanks In Advance..

Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Aditi.

1)ServletPath---> If our DD declares,
and if our browser request is
http://localhost:8080/TestServ/ServOne/*
, the ServletPath is '/ServOne'.
2)I think there is no method RequestPath.
3)PathInfo---> which returns extra path of /ServOne that we have declared in DD, i.e it returns '/*'. Suppose if our browser request is , here PathInfo returns '/AditiServ'.
4)RequestURI--->which returns the browser request without query string, i.e, '/TestServ/ServOne/*'

I think
(1)If my browser request is : http://localhost8080/demo/testExamples/test/test1
If my servlet mapping is /test/*, then what would be the Servlet Path and PathInfo
gives 404 error.



Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Hey Aditi,

Have a look on the below servlet, web.xml entry and output. I think, it should resolve all your doubts -

Servlet code



web.xml entry



The out put in different calls is as follows -

if I call it by http://localhost:8080/TestProject/account/RequestFunctionTest , I get output as

getServletContext().getContextPath() = /TestProject
request.getContextPath() = /TestProject
request.getServletPath() = /account/RequestFunctionTest
request.getRequestURI() = /TestProject/account/RequestFunctionTest
request.getPathInfo() = null


if I call it by http://localhost:8080/TestProject/account/RequestFunctionTest/hello , I get output as

getServletContext().getContextPath() = /TestProject
request.getContextPath() = /TestProject
request.getServletPath() = /account/RequestFunctionTest
request.getRequestURI() = /TestProject/account/RequestFunctionTest/hello
request.getPathInfo() = /hello

if I call it by http://localhost:8080/TestProject/test/account/RequestFunctionTest , I get output as

http 404- resourece not found exception


I think, there is no function by name of getRequestPath().

Regards
Salil Verma





Regards
Salil Verma
Aditi Kamra
Greenhorn

Joined: Aug 25, 2009
Posts: 7

Thanks a lot Chinmaya and Salil, this explanation is of great help

@ Salil,
when you mentioned the browser request as http://localhost:8080/TestProject/account/RequestFunctionTest, correct me if I am wrong ,

then wont the PathInfo be /* ??




Regards,
Aditi

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PathInfo RequestURI ServletPath and RequestPath Query