This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes Forwarding to a different JSP on error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Forwarding to a different JSP on error" Watch "Forwarding to a different JSP on error" New topic

Forwarding to a different JSP on error

adrian mills
Ranch Hand

Joined: Dec 09, 2004
Posts: 63
Hi All,
I am using Struts 1.0. and jboss 3.2.
I am validating my form using the validate method of the ActionForm.

Presently whenever an error occurs it is displayed on the same jsp page.
Eg:I an error occurs while filling a form then the request is sent back to the same Registration.jsp with the errors displayed on the TOP.

Is there a way in Struts 1.0 where the errors are displayed on a different JSP.If yes how can we do this?

If anyone has done it can he explain the steps??

Thanks a lot for your time in advance...

Take Care
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

The way to do this is by moving the validation logic from the form's validate() method to the Action's execute() Method.. or whatever it is in Version 1.0.

When you find an error condition, you instantiate an org.apache.struts.action.ActionErrors object, place an org.apache.struts.action.ActionError object in it using the add() method, and then call the saveErrors() method from the Action class (It's declared in the Action superClass). Within your jsp, insert a <html:errors /> tag where you want the message to be displayed. It will only be displayed if there actually is a message to display.

The important difference between this and doing it in the form is that in the Action, you can forward to a different jsp if there are errors than you do if there are none.
[ February 18, 2005: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: Forwarding to a different JSP on error
It's not a secret anymore!