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

doubt about javabeat mock exam

 
P. Jain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt regarding a question in javabeat mock exam :-

18) What will be the value of the context path, Servlet path and the path info
elements, if the request path is music/Play/album1234?name='xyz' (assuming
that the context of the Web Application is 'music')?
a. Play, album1234 and name='xyz'
b. music, Play and album1234?name='xyz'
c. music, Play and album1234
d. music, Play/ album1234 and name='xyz'

the answer given is d but i think the answer should be b.please clarify...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

music/Play/album1234?name='xyz'

music---contextpath//it should first element

play/album--servlet//url mapping path(i.e,from context to ?)

name='XYZ'--pathinfo//after ?

so aansware is D
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is defined as per the Servlet Speficiation.

The first string after the <protocol>://<hostname>:<portNumber> characters until it finds out the forward slash ("/") is the context root of the application, and the rest of them are all Servlet path till it reaches the request parameters.

You may go through the Servlet Spec and will have more clarification on that.
 
P. Jain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i think so that the servlet name is mapped to longest possible part from the URL.
and the remaining is the path info.
Correct me if i am wrong...
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by P. Jain:
but i think so that the servlet name is mapped to longest possible part from the URL.
and the remaining is the path info.
Correct me if i am wrong...


Servlet Name or Servlet Path?

ServletPath includes everything after the ContextRoot of the application till complete resource being requested excluding the query string parameters.

Hope this is clear!
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the right answer is c

Check out this thread
[ June 25, 2008: Message edited by: Jan Sterk ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jan,

Thanks for the link. Still it may be correct as it all depends on the web.xml and how the url-mapping is configured.

But by default if you don't configure for a directory match, it would fetch the complete path until the query string! Correct? In such case, the option D seems to be an eligible candidate!
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I couldn't find a clear explanation about this matter, I created a simple test myself.

FrontController.java

web.xml

If I type this in the address bar of my browser:
http://localhost:8080/forum/some virtual subdirectory/Front Controller.do?action=add&test=path_etc
this is the output:
*****
URI: /forum/some%20virtual%20subdirectory/Front%20Controller.do
Context path: /forum
Servlet path: /some virtual subdirectory/Front Controller.do
Path info: null
*****


If I type this in the address bar of my browser:
http://localhost:8080/forum/another virtual subdirectory/Front Controller.do?action=add&test=path_etc
this is output:
*****
URI: /forum/another%20virtual%20subdirectory/Front%20Controller.do
Context path: /forum
Servlet path: /another virtual subdirectory
Path info: /Front Controller.do
*****


Looks to me that
- if the servlet is found with an exact match, then the servlet path goes from the context path up to (and does not include) the query string; so it is the url-pattern in the DD. Path info is null.
- if the servlet is found with a directory match, then the servlet path is the url-pattern in the DD without the /*. The path info is 'the wildcard', that is, the rest without the query string.
- the query string is not part of context path, servlet path or the path info

What surprises me is that the query string isn't included in the RequestURI. One explanation could be that the container translates the query string to request parameters, then strips the QS from the URI, then forwards it to service(..) of Servlet.
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering the above, the Javabeat question is not complete.

C is the only answer that could be right. That is, only if the <url-pattern> in the DD is defined as /Play/* . (Not even considering the missing leading /'s in the answers ).

If it is defined as an exact match in the DD, then none of the answers are right.

Pretty bad question, if you ask me On the other hand, it got us thinking about it and thanks to that, we have become Path-masters now!
[ June 26, 2008: Message edited by: Jan Sterk ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jan,

Thats a great work. Thats what i have told earlier that it depends on the entry in web.xml
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic