• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding to a different JSP on error

 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

Bye
Take Care
Adrian
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian,

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic