• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet-mapping question...

 
Neil Mc
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what would happen if, on receiving a request, we could map that request to more than one servlet - and one was just as specific as the other? e.g. if we had two <servlet-mapping> tags, each with a <url-pattern> of, say...

<url-pattern>*.stuff</url-pattern> ?

Is this valid ?

Just curious is all.

Thanks.
 
Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot do that. When you'll try to deploy this, Tomcat would throw exceptions like 'Child name, not unique etc etc'.
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neil,

Is this a valid scenario?

<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlet/HelloWorldExample.stuff</url-pattern>
</servlet-mapping>

Cheers
 
Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitish,

your scenario is valid. There can be multiple url-patterns to a single servlet but there cannot be multiple servlets with the same url pattern.


cheers
 
Sami Sayeed
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bahadar khan,
If the url pattern is duplicated as the following the container wont throw any error.
<servlet>
<servlet-name>Hey</servlet-name>
<jsp-file>/pageContextAttr.jsp</jsp-file>
</servlet>
<servlet>
<servlet-name>Hey1</servlet-name>
<jsp-file>/setAttr.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Hey</servlet-name>
<url-pattern>/*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Hey1</servlet-name>
<url-pattern>/*.do</url-pattern>
</servlet-mapping>

Only if you specify the pattern to a specific file like hello.do for both servlets would you get an error.
 
Abhishek Mahanty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm not quite sure about this . So if a client requests a xyz.do file, which resource will handle the request ?

Hey (i.e. /pageContextAttr.jsp)
or
Hey1 (i.e. /setAttr.jsp)


Abhi.
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the similar discussion

regards,
MZ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic