Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping client requests to resoures

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Here is a question on servlet mapping:
Consider the following code-snippet in the deployment-descriptor from the web-application SCWCD. To which rule will the following request URI map: /SCWCD/door/file.hall?
<!-- Rule 1 -->
<servlet-mapping>
<servlet-name>VauxHallServlet</servlet-name>
<url-pattern>/hall/*</url-pattern>
</servlet-mapping>

<!-- Rule 2 -->
<servlet-mapping>
<servlet-name>VauxHallServlet</servlet-name>
<url-pattern>/hall/hall/*</url-pattern>
</servlet-mapping>

<!-- Rule 3 -->
<servlet-mapping>
<servlet-name>VauxHallServlet</servlet-name>
<url-pattern>/door/*</url-pattern>
</servlet-mapping>

<!-- Rule 4 -->
<servlet-mapping>
<servlet-name>VauxHallServlet</servlet-name>
<url-pattern>*.hall</url-pattern>
</servlet-mapping>

1. Rule 1.
2. Rule 2.
3. Rule 3.
4. Rule 4.
5. Default servlet

The ans given is Rule 3 i-e VauxHallServlet.
It's obvious that 1 and 2 are incorrect.
But somehow, I can't figure out that why Rule 4 is not executed. Can anybody throw some light on this.

Thanks,
Reema
 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The rules for servlet mapping

The container first look for exact match if cannot find the exact match it look for directory match and if it cannot find a directory match it look for extension match.

For this URI
/SCWCD/door/file.hall?
We have got the directory match
/door/*

so answer is VauxHallServlet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic