JBridge

JBridge: Certification Question Of The Day

JBridge Home >> Certification Questions >> Today's Question Wednesday 7th May 2003

Given a web application with a context root of MyWebApp with a servlet mapping as follows:

<servlet-mapping>
	<servlet-name>MyServlet</servlet-name>
	<url-pattern>/MyServlet/*</url-pattern>
</servlet-mapping>
And a request to the web application in this form:
http://localhost:8080/MyWebApp/MyServlet/action/cinema?film=Fargo
What is returned from the following code in MyServlet?
request.getPathInfo();



A A String containing “/action/cinema”
B A URL in the form “http://localhost:8080/MyWebApp/MyServlet/action/cinema”
C A URL in the form “http://localhost:8080/MyWebApp/MyServlet”
D A String containing “/MyWebApp/MyServlet/action/cinema”
E A String containing “/cinema”
F A String containing “/action/cinema?film=Fargo”
G A URI in the form “/MyWebApp/MyServlet”
H Nothing is returned as the code could never be executed: the request URL does not find MyServlet.
Page down for the answer...











































The Answer

The correct answer is A, a String containing “/action/cinema”.
As getPathInfo() returns a String type, not a URL (which exists as a type) or URI (which doesn’t), this excludes answers B, C and G.
Path information is a kind of parameter passing within the URL – information after the portion which maps to a resource on the server (in this example, up to “…/MyServlet/”). So D can’t be right – the “MyWebApp/MyServlet/” part should not be included. And answer E only contains part of the path information, so that’s wrong too.
However, path information does not include the query string (everything including and after the question mark); there’s a separate mechanism (request.getParameter()) to obtain parameters from this portion. So answer F has to be wrong.
Any valid URL beginning with http://localhost:8080/MyWebApp/MyServlet will find MyServlet, so H is wrong.


EMail: dbridgewater@jbridge.co.uk
Phone: +44 (0)1943 877414
Fax: +44 (0)1943 877414
Mail: David Bridgewater, Willow Dene, Bradford Road, Menston, Ilkley, West Yorkshire, LS29 6ED, UK
Copyright © 2003 David Bridgewater. All rights reserved.