• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PathInfo RequestURI ServletPath and RequestPath Query

 
Aditi Kamra
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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




 
Aditi Kamra
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic