File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes servlet-mapping question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "servlet-mapping question..." Watch "servlet-mapping question..." New topic
Author

servlet-mapping question...

Neil Mc
Ranch Hand

Joined: Oct 20, 2003
Posts: 32
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

Joined: Jun 19, 2003
Posts: 81
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

Joined: Aug 25, 2003
Posts: 118
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

Joined: Jun 19, 2003
Posts: 81
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

Joined: Oct 05, 2004
Posts: 39
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

Joined: Jan 26, 2004
Posts: 19
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.


SCEA-I, SCBCD 1.3, SCWCD 1.4, SCJP 1.4, OCP
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3178
    
    3
check the similar discussion

regards,
MZ


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet-mapping question...
 
Similar Threads
specify a default servlet in DD
url matching doubt
is not available
Servlet mapping
Problems with servlet-mapping to redirect some JSPs...