problem: j2ee, web.xml, about set 2 servlet mapping to the same url

S

sods

Hi, all,

I'm newer for j2ee.

I find in some /WEB-INF/web.xml,
there are 2 different servlets mapping to the same url-pattern.

Doesn't it cause problem?
I don't know which will process and give response, when request come.
Whether the two servlet will share the same request obj, or not?

maybe this is designed for monitor servlet.
but i can't imagine what happen with two response to a request.


-Wisdo
 
C

Chris Smith

sods said:
I find in some /WEB-INF/web.xml,
there are 2 different servlets mapping to the same url-pattern.

This shouldn't happen. Can you give an example? Maybe there's
something else really happening there.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
J

josh.s17

Can you paste the relevant section of the web.xml file into your post
so we know exactly what you mean.
 
S

sods

Chris Smith said:
This shouldn't happen. Can you give an example? Maybe there's
something else really happening there.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

of course.

example:

<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>

<servlet-class>com.xxxx.webapp.common.struts.XXServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>validating</param-name>
<param-value>@xx.struts.validate.dtd@</param-value>
</init-param>
<init-param>
<param-name>xx.config.root</param-name>
<param-value>@xx.config.root@</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>action_tmp</servlet-name>

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>

<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action_tmp</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

any ideas?

-sods
 
C

Chris Smith

sods said:
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action_tmp</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

This is incorrect. I don't see anything in the servlet specification
that specifically defines how a servlet container will deal with this
situation, but there are several statements that imply that it should
choose the first mapping and ignore the second one. However, since that
isn't stated clearly, if such a behavior were observed for some specific
implementation, it would be better to remove the second unused mapping
element to avoid confusion and potential for the web application to
break on future versions of the servlet container.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
S

sods

Can you paste the relevant section of the web.xml file into your post
so we know exactly what you mean.
the problem is just
there are two servlets.

servlet1:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.xxxx.webapp.common.struts.XXServlet</servlet-class>
</servlet>

servlet2:
<servlet>
<servlet-name>action_tmp</servlet-name>

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>

but they mapping to the same url-pattern, like follow.
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action_tmp</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

when a request /$(CONTEXTPAT)/login.do come, I don't know what happen.

Chris think it's incorrect according to the J2EE Specification, and
dangerous to common usage.

-sods
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top