You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Manomohan K Kalathil <ma...@mindtree.com> on 2002/12/14 15:05:43 UTC

More than one servlet mapping

Hi all, 
	The struts documentation
(http://jakarta.apache.org/struts/userGuide/configuration.html#dd_config)
says that "WARNING - Struts will not operate correctly if you define more
than one <servlet-mapping> element for the controller servlet."
	I would like to know the reason behind this. Is it that the
controller will not be able to differentiate between request to similar URLs
which differ by the extension ?
	Let us take a simple example, suppose I were to map the action to two
extensions, as in:

<servlet-mapping>
     <servlet-name>action</servlet-name>
     <url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
     <servlet-name>action</servlet-name>
     <url-pattern>*.act</url-pattern>
</servlet-mapping>

	One would think that the Action Servlet will have trouble in figuring
out how to handle the following URLs 
http://hostname/context/getBalance.do and
http://hostname/context/getBalance.act. This is because the action mapping
does not contain the extensions. 
	<action path="/getBalance" type="com.myco.BalanceAction" />

Is there any other known issue in the use of more than one mapping to the
action servlet. 

Regards
Mano


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: More than one servlet mapping

Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Sat, 14 Dec 2002, Manomohan K Kalathil wrote:

> Date: Sat, 14 Dec 2002 19:35:43 +0530
> From: Manomohan K Kalathil <ma...@mindtree.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Subject: More than one servlet mapping
>
> Hi all,
> 	The struts documentation
> (http://jakarta.apache.org/struts/userGuide/configuration.html#dd_config)
> says that "WARNING - Struts will not operate correctly if you define more
> than one <servlet-mapping> element for the controller servlet."
> 	I would like to know the reason behind this. Is it that the
> controller will not be able to differentiate between request to similar URLs
> which differ by the extension ?
> 	Let us take a simple example, suppose I were to map the action to two
> extensions, as in:
>
> <servlet-mapping>
>      <servlet-name>action</servlet-name>
>      <url-pattern>*.do</url-pattern>
> </servlet-mapping>
> <servlet-mapping>
>      <servlet-name>action</servlet-name>
>      <url-pattern>*.act</url-pattern>
> </servlet-mapping>
>
> 	One would think that the Action Servlet will have trouble in figuring
> out how to handle the following URLs
> http://hostname/context/getBalance.do and
> http://hostname/context/getBalance.act. This is because the action mapping
> does not contain the extensions.
> 	<action path="/getBalance" type="com.myco.BalanceAction" />
>
> Is there any other known issue in the use of more than one mapping to the
> action servlet.

Yes.  It won't work :-).

The problem isn't on the incoming requests being mapped to the controller
servlet correctly -- it's when Struts is asked to dynamically generate a
URL for an action (such as in an <html:form> tag).  There is no easy way
to tell which of the mappings should be used, and also some pathological
cases where the application treats requests with the different extensions
differently (which Struts would know nothing about).

Although advanced users might be able to craft a combination of things
that would work, it would be a quicksand trap for mere mortals.
Therefore, Struts only remembers a single mapping pattern for the
controller servlet.

>
> Regards
> Mano
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>