• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Doubt about getContextPath(), getServletPath, getPathInfo()

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a doubt about getContextPath(), getServletPath and getPathInfo()
If we use a ".jsp", getPathInfo() will be always null ?

http://localhost:8080/myApp/SelectStuff.do
=> using of "result.jsp"

getContextPath(): /myApp
getServletPath(): /result.jsp
getPathInfo(): null

http://localhost:8080/myApp/xxx/xxx/SelectStuff.do
=> using of "result.jsp"

getContextPath(): /myApp
getServletPath(): /xxx/xxx/result.jsp
getPathInfo(): null

http://localhost:8080/myApp/xxx/
=> map to "result.jsp"

getContextPath(): /myApp
getServletPath(): /xxx/
getPathInfo(): null


But if we use anything else, by example a ".html"

http://localhost:8080/myApp/index.html

getContextPath(): /myApp
getServletPath(): null
getPathInfo(): /index.html


http://localhost:8080/myApp/xxx/index.html

getContextPath(): /myApp
getServletPath(): /xxx
getPathInfo(): /index.html

http://localhost:8080/myApp/xxx/

getContextPath(): /myApp
getServletPath(): null
getPathInfo(): /xxx/

Am I right or not ?

Thanks in advance !
 
Creator of Enthuware JWS+ V6
Posts: 3346
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Angy,

If we use a ".jsp", getPathInfo() will be always null ?


Not always: it depends on your servlet-mapping.

For example:

When you now use the following URL:
http://localhost:8080/myApp/A/hallo?q=a

getServletPath() /A
getContextPath() /myApp
getPathInfo() /hallo
getQueryString() q=a


or http://localhost:8080/myApp/A/B/C/hallo?q=a

getServletPath() /A
getContextPath() /myApp
getPathInfo() /B/C/hallo
getQueryString() q=a



You can use a simple jsp like this to verify:

An HTML file is always part of the getPathInfo()

Regards,
Frits
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect !

Thank you ! :-)
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic