Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

COnfused about ServletPath Vs PathInfo

 
Ritu varada
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request URI = contextPath + servletPath + pathInfo

and the following examples were given:

Request path: /games/tictactoe/welcome.html
-Context path = /games
-Servlet path: /tictactoe
-Path info: /welcome.html

Request path: /games/registration/StartServlet
-Context path: /games
-Servlet path: /registration/StartServlet
-Path info: null

Request path: /games/Search/1234?query=Yamaha+R6
-Context path: /games
-Servlet path: /Search
-Path info: /1234

I am wondering if there's an easy way of telling which path is which. For example, in the last example, can it also be Context path: /games/Search, Servlet path=/1234 and Path info=null? How can one tell the servlet path from the path info?


Thanks a lot
 
Francois Roland
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The context path is given by your servlet engine. It refers to the path assigned to your complete web-app. I'm not completely sure of this, but I think that it can't span more than one "directory" in your URL.

The servlet path is referring to the url-pattern element of your deployment descriptor. Given the following:

if you request path is "/games/Search/1234?query=Yamaha+R6", the servlet engine first finds the context path "/games" which corresponds to your web application and then finds the pattern. "/Search" is the servlet-path.

Everything that expands beyond the servlet path, excluding the request parameters, is the path info. In our case, it is "/1234".
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request path: /games/Search/1234?query=Yamaha+R6
-Context path: /games
-Servlet path: /Search
-Path info: /1234

I am wondering if there's an easy way of telling which path is which. For example, in the last example, can it also be Context path: /games/Search, Servlet path=/1234 and Path info=null? How can one tell the servlet path from the path info?

Probably not, but you could have:

context path: games
url-pattern (servlet-path): Search/1234
path info = null

Remember that the url-pattern can contain anything you want the client to see as link to your servlet. The servlet internal name is hidden from the client and you realize the mapping between external and internal name throught the servlet-mapping element in the DD.

Thanks a lot[/QB]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic