File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes ensuring valid forwards Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ensuring valid forwards" Watch "ensuring valid forwards" New topic

ensuring valid forwards

Dan Tenenbaum

Joined: Apr 19, 2005
Posts: 6
My codebase has a lot of lines like this in struts actions:
return mapping.findForward("foo");

If I make a typo and it turns out that "foo" is not a valid forward according to the struts config file, when I hit the action in the browser, I get a blank page. Not my designated error page.

Is there some sort of struts-centric way to ensure that an exception is thrown and my error page appears? I just want to know if there is an existing mechanism to do this. I could easily write a method to do it (to be called instead of mapping.findForward()) but it seems that this is something Struts should handle.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
the closest struts handles unknown is the action mapping attribute 'unknown' which becomes the action to call when a is not found. i don't believe there is such a thing for forwarding. you'll need to write your own. -/a

-/a<br />certified slacker...yes, my last name is 'do' - <a href="" target="_blank" rel="nofollow"></a>
Jack Wiesenthaler
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
One way is possibly defining your own exception class and throwing it when a mapping.findforward returns a null ActionForward. Then in the action mapping within struts-config you can use the exception tag with your exception type mapped to the specified error jsp page.
I agree. Here's the link:
subject: ensuring valid forwards
It's not a secret anymore!