Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Three question about Servlet Mapping

 
Hai Lin
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
Suppose there's a web application called colorapp.
then in the web.xml,

<servlet-mapping>
<servlet-name>RedServlet</servlet-name>
<url-pattern>/red/*</url-pattern>
</servlet-mapping>

The book SCWCD exam study kid said "URI /colorapp/red will match RedServlet."
But I have doubt: The url-pattern is /red/*, that means at least URI should end with "/", so why /colorapp/red can match it? If we say the last "/" in url-pattern doesn't matter, then take a look the following mapping,
<servlet-mapping>
<servlet-name>BlueServlet</servlet-name>
<url-pattern>/blue/</url-pattern>
</servlet-mapping>

The URI /colorapp/blue doesn't match BlueServlet, That means the last "/" in the servlet mapping is very important!
So, my confusion is that
1) why the first mapping /colorapp/red is fine?
2) how about /colorapp/red/?
3) any "?" used in the url-pattern mapping?

Greatly appreciate your reply.
 
dick dijk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/red/* in the servet mapping means : match anything that starts with "/red".
Therefore "/colorapp/red" matches this pattern.

Dick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic