Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about getContextPath(), getServletPath, getPathInfo()

 
Fabian Angy
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 !
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2451
96
Android Chrome Eclipse IDE
  • 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 ! :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic