No problem, I think I might have read a little too much into your
original post too :)

I was thinking that you were looking for a more complex solution, but
wildcards are sufficient for most needs, especially if your namespace
is /. 

I think there is an exception that does get thrown when no action is
mapped to the request. I am testing it right now and I don't see an
exception in my app server console, but it does show a stack trace. I'd
have to look in the code to be sure. Anyhow, if wildcards work, you're
in good shape!

-Wes

On Sat, 2008-11-08 at 17:13 -0800, delsvr wrote:
> Thanks for the quick reply.
> 
> I may have spoken too soon about the wildcard mapping. I originally had the
> "enable.SlashesInActionNames" property set to true before trying the
> wildcard, thinking that would make the most sense if I want to match
> everything under a namespace; however, setting it to false is actually what
> does the trick.
> 
> i.e. with the property as false, along with the "action.extension" property
> set to empty,
> 
> <package name="default" extends="struts-default">
>    <action name="*"><result></result></action>
> </package>
> 
> catches all URLs under the context path (for me).
> 
> I'm not sure if I would consider this request as coupling Struts with the
> Servlet, though. It's just a provision to handle missing actions. It doesn't
> necessarily need to return a 404 response. I'm surprised it doesn't at least
> return an exception for me to work with.
> 
> At any rate, thanks for the tip. UnknownHandler looks like a good solution,
> too. I'll try it out soon.
> 
> -- delsvr
> 
> 
> Wes Wannemacher wrote:
> > 
> > I can sort of understand your request, but there are a few things to
> > consider. First off, Struts tries really hard to be de-coupled from the
> > servlet / JSP specs, so what you're asking is not quite as easy and some
> > quick configuration hacks. Probably the easiest way to get what you want
> > is to configure an error-page in web.xml. If memory serves, it is
> > something like the following - 
> > 
> >     <error-page>
> >         <error-code>
> >             404
> >         </error-code>
> >         <location>
> >             /404.html
> >         </location>
> >     </error-page>
> > 
> > If you really want to try to handle it in Struts, the wildcard mapping
> > is the easiest thing, but as you said, it is likely to only be valid
> > within the the package that the wildcard is configured. 
> > 
> > Another option that may help you to get what you want is to look at
> > implementing a custom UnknownHandler. The JavaDoc (which doesn't say
> > much) is here - 
> > 
> > http://www.opensymphony.com/xwork/api/com/opensymphony/xwork2/UnknownHandler.html
> > 
> > For an example, check the conventions plugin (or codebehind) to see
> > their implementation. 
> > 
> > -Wes
> > 
> > 
> > On Sat, 2008-11-08 at 13:52 -0800, delsvr wrote:
> >> I've been searching high and low for a solution to this simple problem,
> >> but I
> >> can't find anything:
> >> 
> >> How can I get Struts2 to handle non-existing actions, globally? I thought
> >> a
> >> global exception mapping would do it, but it doesn't seem like an
> >> exception
> >> is being thrown when an action can't be found... or maybe one is, but
> >> it's
> >> handled by the dispatcher? I've also tried a wildcard action mapping, but
> >> this is insufficient as it only seems to match missing actions within its
> >> respective namespace.
> >> 
> >> If a missing action does throw an exception, may someone explain why this
> >> struts.xml configuration is failing to catch it:
> >> 
> >> <struts>
> >>    <constant name="struts.devMode" value="false" />
> >>    <constant name="struts.action.extension" value="" />
> >>    <constant name="struts.enable.SlashesInActionNames" value="true" />
> >>    
> >>    <package name="default" namespace="/" extends="struts-default">
> >>            <global-results>
> >>                    <result name="error">/error/404.html</result>
> >>            </global-results>
> >> 
> >>            <global-exception-mappings>
> >>                    <exception-mapping exception="java.lang.Exception" 
> >> result="error" />
> >>            </global-exception-mappings>
> >>    
> >>            <action name="Index">
> >>                    <result>/index.html</result>
> >>            </action>
> >>    
> >>    </package>
> >>    
> >> </struts>
> >> 
> >> Thanks!
> >> 
> >> -- delsvr
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Struts2%3A-Handling-a-Missing-Action-%28404%29-tp20400822p20402372.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to