struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David G. Friedman" <hum...@ix.netcom.com>
Subject RE: How To Handle Mis-Typing of URL By Users
Date Mon, 20 Sep 2004 03:51:37 GMT
Caroline,

Think of the one 'unknown="true"' action-mapping as a catch-all.  The path
set on that particular mapping isn't important - any url that gets given to
the struts ActionServlet that didn't match one of your other defined actions
will go do that one.  To give a more precise example, take the below simple
set of make-believe action mappings:

<action-mappings>
	<action path="/listArticles"
		unknown="true"
		type="mine.ListArticleAction" />

	<action path="/readArticle"
		type="mine.ReadArticleAction" />
</action-mappings>

Let's say my site wants to let you list articles or read articles.  You'd
have to visit /readArticle.do?id=something to read a particular article.
For all other *.do strings, we want to list the articles.  Technically,
/listArticles.do (the "path") is the url that pulls up the article list.
BUT, we have the unknown="true" on that action so any mistyped Struts
path/URL  will simply list the articles.  That is the key noun "Struts URL".
If the URL wasn't a Struts mapped URL (no *.do or /do/*, depending on your
web.xml pattern mapping), then you need to arrange an error page for the 404
(or whatever code it is) web server error.  In an application server such as
tomcat, you can set it in the web.xml.  In apache, it's in the ".htaccess"
file or the web server configuration file under that virtual host (or the
default configuration), and in ISS, it is a property under one of the tabs
(I last used IIS too long ago to remember the tab name under the web site
properties pop-up).

No matter how many OTHER actions you have defined, anything that doesn't
match will go to that unknown="true" mapping, IF you have one (it's not
mandatory to have an unknown="true" setup).

I hope that is a better explanation.

Regards,
David

-----Original Message-----
From: Caroline Jen [mailto:jiapei_jen@yahoo.com]
Sent: Sunday, September 19, 2004 9:03 PM
To: Struts Users Mailing List
Subject: RE: How To Handle Mis-Typing of URL By Users


Thanks for your reply.

I am still a little confused and need a further help.

My confusion stems from "if your URL is defined as
http://www.yoursite.com/myapp/someAction.do
but the visitor ended up typing in a Struts URL you
never configured in your struts-config.xml file(s)
such as
http://www.yoursite.com/myapp/someFraction.do"

There is no way to predict what kind of URL the
visitor ends up with his/her mis-typing.  Therefore,
how do we prepare the path attributes in the action
mapping of the struts-config.xml file?

<action name="default"
        path="/someFraction"  // unable to predict
 	unknown="true"
 	forward="/error404.jsp" />

Caroline
--- "David G. Friedman" <humble@ix.netcom.com> wrote:

> Jen,
>
> The question is are you trying to catch mistyped
> Struts URLS OR regular URL
> resources such as JSPs, HTML, CSS, Javascript
> includes, Images, etc.?
> For the former, you're barking up the wrong tree
> (see below).  For the
> latter, your error-page code should work UNLESS
> those file types are NOT
> being handled by your Java Server (perhaps locally
> by a front-end Apache?).
>
> Some key documentation (uh, oh, I'm saying RTFM
> aren't I? LOL):
>
http://struts.apache.org/userGuide/building_controller.html#actionmapping
>
> It explains a wonderful struts-config.xml Action
> Mapping feature:
>
> unknown - Set to true if this action should be
> configured as the default for
> this application, to handle all requests not handled
> by another action. Only
> one action can be defined as a default within a
> single application.
>
> So, if your URL is defined as
> http://www.yoursite.com/myapp/someAction.do
> but the visitor ended up typing in a Struts URL you
> never configured in your
> struts-config.xml file(s) such as
> http://www.yoursite.com/myapp/someFraction.do, this
> struts-config.xml
> mapping would catch it and other Struts URL
> mistypings:
>
> <action name="default"
> 	path="/someFraction"
> 	unknown="true"
> 	forward="/error404.jsp" />
>
> And yes, I have used the "unknown" parameter at
> least once in a Struts v1.1
> deployment, though not recently.
>
> Regards,
> David
>
> -----Original Message-----
> From: Caroline Jen [mailto:jiapei_jen@yahoo.com]
> Sent: Thursday, September 16, 2004 9:34 AM
> To: Struts Users Mailing List; Craig McClanahan
> Subject: Re: How To Handle Mis-Typing of URL By
> Users
>
>
> Hi, I prepared the error404.jsp (simply typed in a
> warning sentence) and placed the file in the
> AppName/WEB-INF/web.xml file this way:
>
>   <welcome-file-list>
>     <welcome-file>index.jsp</welcome-file>
>   </welcome-file-list>
>   <error-page>
>     <error-code>404</error-code>
>     <location>/error404.jsp</location>
>   </error-page>
>   <!--  taglibs -->
>   <taglib>
>      <taglib-uri>/tags/struts-bean</taglib-uri>
>
>
<taglib-location>/WEB-INF/lib/struts-bean.tld</taglib-location>
>
>   </taglib>
>
> I tested mis-typing.  But, my sentence; i.e. the
> error
> page that I prepared does not show up.
>
> Would you be more clear about "map this condition
> directly to a Struts action or URL mapped directly
> to a servlet." in the servlet 2.4 environment?  I
> still do not have any idea about how the mapping
> should be done in the struts-config.xml file.
>
>
>
> --- Craig McClanahan <craigmcc@gmail.com> wrote:
>
> > On Wed, 15 Sep 2004 13:06:01 -0400, Bill Siggelkow
> > <billsigg@bellsouth.net> wrote:
> > > Place this stancza below your welcome-file-list
> in
> > your web.xml. You can
> > > use a static HTML page or a JSP.
> > >
> > > <error-page>
> > >      <error-code>404</error-code>
> > >      <location>/error404.jsp</location>
> > > </error-page>
> > >
> >
> > In a servlet 2.4 environment, you could also map
> > this condition
> > directly to a Struts action or URL mapped directly
> > to a servlet.
> >
> > > -Bill Siggelkow
> > >
> >
> > Craig
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> > user-help@struts.apache.org
> >
> >
>
>
>
>
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
>
>




__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message