You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hardee, Tony" <To...@ps.net> on 2001/02/15 15:33:54 UTC

Struts Example using Prefix Matching

Does anyone have an example Struts application using prefix mapping where
all URLs that start after the context path are routed to the ActionServlet?
I would like a rigid model 2 architecture where all requests are routed
through the controlling servlet.
  

Re: Struts Example using Prefix Matching

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Craig Tataryn wrote:

> In your web.xml file change:
>
> <servlet-mapping>
>     <servlet-name>action</servlet-name>
>     <url-pattern>*.do</url-pattern>
> </servlet-mapping>
>
> TO:
>
> <servlet-mapping>
>     <servlet-name>action</servlet-name>
>     <url-pattern>*</url-pattern>
> </servlet-mapping>
>

The legal pattern for this would actually be "/*".  But, if you do this, you're
going to discover another problem -- everything stops working :-(.

Why?  Because the "/*" mapping covers JSP pages as well.  Now, when you try to
forward to your JSP page with a path like "/mainmenu.jsp", you will actually be
mapped back to the controller servlet again, which will probably say
"unrecognized mapping".

In servlet 2.2, there is no graceful way to ensure that you have processing logic
imposed on every single request.  Thus, you'll find it necesary to do some sanity
checks at the tops of your JSP pages (such as the <app:checkLogon> tag used in
the example application to verify that the user has logged in).

In servlet 2.3, the new Filter capability allows you to map a Filter to "/*" (so
it will see every request), without disrupting the mapping of "*.jsp" to the JSP
servlet.  However, we cannot count on 2.3 support being broadly available for
quite a while yet (outside of Tomcat 4.0-beta-1 and a couple of others), so it is
premature to base Struts on these capabilities.

>
> Craig T.
>

Craig McClanahan



Re: Struts Example using Prefix Matching

Posted by Craig Tataryn <Cr...@msdw.com>.
In your web.xml file change:

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

TO:

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*</url-pattern>
</servlet-mapping>

Craig T.

"Hardee, Tony" wrote:

> Does anyone have an example Struts application using prefix mapping where
> all URLs that start after the context path are routed to the ActionServlet?
> I would like a rigid model 2 architecture where all requests are routed
> through the controlling servlet.