• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet path, context path and path info.

 
Srinu Nanduri
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've come across the following questions in the Javabeat mock exams.

Q1) Pick out the context path, Servlet path and path information from the request
path '/books/Find/abcd?query=Java' (assuming that the context is 'books')?
a. '/books', '/Find' and '/abcd'
b. '/books', '/Find/abcd' and 'query=Java'
c. '/books/Find', '/abcd' and 'query=Java'
d. None of the above.

A1) a.
Option a is correct. The context path, Servlet path and the path information are '/books',
'/Find' and '/abcd' respectively.

Q2) 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'

A2) d
Option d is correct.

I some how find the answers inconsistent. If the answer to Q2 is correct, the answer to Q1 should be b.

Another one -

The following question

Q) Which of the following interfaces can be used to acquire a reference to
ServletContext object?
a. HttpServletRequest
b. HttpServletResponse
c. HttpSession
d. HttpServletConfig
e. ServletConfig

has the answer a and e according to JavaBeat. I assume this is wrong and the answer should be only e.

Could some one please clarify.

Thanks in advance,

Cheers, Srinu
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it is time for someone to jump in. Based on the questions provided it is unlikely I will be relying on Javabeat. For one thing, it seems the servlet mapping is necessary to determine some of the answers. For example, for "/books/Find/abcd?query=Java", the context path is obvious. However, if a mapping was found to contain "<url-pattern>/Find/abcd/*</url-pattern>", then it would appear "/Find/abcd" is the servlet path, but if a mapping was found to contain "<url-pattern>/Find</url-pattern>", then it would appear that "/Find" is the servlet path. I am weak in this area, so the above may not completely correct. However, the point of this post is, I find this area is difficult enough even when mappings are provided. Furthermore, since the explanation in the spec is provided with associated servlet mapping, I find it hard to believe the real exam would do it any different.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic