• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

servlet-mapping question...  RSS feed

 
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.
 
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'.
 
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
 
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.
 
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.
 
Ranch Hand
Posts: 3450
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the similar discussion

regards,
MZ
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!