You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2004/09/15 17:47:40 UTC
How To Handle Mis-Typing of URL By Users
I have many links in my web site. And, for example;
the name of my web site is XYZCompany. and we type
http://localhost:8080/XYZCompany to get to view the
web site.
For example, there is a link 'directory' to get to the
web page that shows the directory of the company. And
users can type
http://localhost:8080/XYACompany/directory
to get to it.
When users mis-type the word 'directory', I would like
to show a page saying 'the requested page cannot be
found'. How do I handle it in Struts.
I think that I have to prepare a .jsp page with the
message 'the requested page cannot be found' in it. I
think that the control should be in the
struts-config.xml. But, I do not know how to do it.
Please help me.
_______________________________
Do you Yahoo!?
Express yourself with Y! Messenger! Free. Download now.
http://messenger.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: How To Handle Mis-Typing of URL By Users
Posted by "David G. Friedman" <hu...@ix.netcom.com>.
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" <hu...@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 <cr...@gmail.com> wrote:
>
> > On Wed, 15 Sep 2004 13:06:01 -0400, Bill Siggelkow
> > <bi...@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
RE: How To Handle Mis-Typing of URL By Users
Posted by Caroline Jen <ji...@yahoo.com>.
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" <hu...@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 <cr...@gmail.com> wrote:
>
> > On Wed, 15 Sep 2004 13:06:01 -0400, Bill Siggelkow
> > <bi...@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
RE: How To Handle Mis-Typing of URL By Users
Posted by "David G. Friedman" <hu...@ix.netcom.com>.
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 <cr...@gmail.com> wrote:
> On Wed, 15 Sep 2004 13:06:01 -0400, Bill Siggelkow
> <bi...@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
Re: How To Handle Mis-Typing of URL By Users
Posted by Caroline Jen <ji...@yahoo.com>.
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 <cr...@gmail.com> wrote:
> On Wed, 15 Sep 2004 13:06:01 -0400, Bill Siggelkow
> <bi...@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
Re: How To Handle Mis-Typing of URL By Users
Posted by Craig McClanahan <cr...@gmail.com>.
On Wed, 15 Sep 2004 13:06:01 -0400, Bill Siggelkow
<bi...@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
Re: How To Handle Mis-Typing of URL By Users
Posted by Bill Siggelkow <bi...@bellsouth.net>.
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>
-Bill Siggelkow
Caroline Jen wrote:
> I have many links in my web site. And, for example;
> the name of my web site is XYZCompany. and we type
> http://localhost:8080/XYZCompany to get to view the
> web site.
>
> For example, there is a link 'directory' to get to the
> web page that shows the directory of the company. And
> users can type
> http://localhost:8080/XYACompany/directory
>
> to get to it.
>
> When users mis-type the word 'directory', I would like
> to show a page saying 'the requested page cannot be
> found'. How do I handle it in Struts.
>
> I think that I have to prepare a .jsp page with the
> message 'the requested page cannot be found' in it. I
> think that the control should be in the
> struts-config.xml. But, I do not know how to do it.
> Please help me.
>
>
>
> _______________________________
> Do you Yahoo!?
> Express yourself with Y! Messenger! Free. Download now.
> http://messenger.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org