• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ensuring valid forwards

 
Dan Tenenbaum
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the closest struts handles unknown is the action mapping attribute 'unknown' which becomes the action to call when a xxx.do is not found. i don't believe there is such a thing for forwarding. you'll need to write your own. -/a
 
Jack Wiesenthaler
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic