JBridge

JBridge: Certification Question Of The Day

JBridge Home >> Certification Questions >> Question for Saturday May 17th 2003 Saturday May 17th 2003
Which of the following are illegal servlet mappings? (3 correct answers)

A 
<servlet-mapping>
  <servlet-name>ProductList</servlet-name>
  <url-pattern>*</url-pattern>
</servlet-mapping>

B 
<servlet-mapping>
  <servlet>ProductList</servlet>
  <url-pattern>/ProductList</url-pattern>
</servlet-mapping>

C 
<servlet-mapping>
  <servlet-name>ProductList</servlet-name>
  <url-pattern>/ProductList</url-pattern>
</servlet-mapping>

D 
<servlet-mapping>
  <servlet-name>ProductList</servlet-name>
  <servlet-url>*.*</servlet-url>
</servlet-mapping>

E 
<servlet-mapping>
  <servlet-name>ProductList</servlet-name>
  <url-pattern>/ProductList/*</url-pattern>
</servlet-mapping>

F 
<servlet-mapping>
  <jsp-name>productList.jsp</jsp-name>
  <url-pattern>/productSearch/*</url-pattern>
</servlet-mapping>

G 
<servlet-mapping>
  <servlet-name>ProductList</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>

Page down for the answer...











































The Answer

A, B and F are the the correct answers, as they are all illegal mappings. B and F include illegal element names (<servlet> and <jsp-name>), while the asterisk on its own for the url-pattern in answer A will cause the container to choke on start up.
The remaining mappings are fine. Answer C is the conventional way to do the mapping. Answer E is conventional, and allows path information to follow the servlet name in the request.
Answer G turns ProductList into the default servlet: if no other more specific mappings match a given request, the ProductList servlet will be executed.
Answer D is legal, but is probably not what the administrator intended. The url-pattern looks like a wildcard file name mapping (anyName.anyExtension). So you might expect that a URL like http://localhost:8080/webAppName/search.txt would map to the ProductList servlet. But this is not the case. The first asterisk is indeed a wildcard. The second is just a character to be matched. So only URLs like http://localhost:8080/webAppName/search.* will map to the ProductList servlet.


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.