Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionForward Question

 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How will I carry the ActionMessages or ActionErrors to the forwarding jsp if i use this:



instead of this

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ActionErrrors are stored in the request. You put them there by calling the saveErrors(..) method on your Action's superclass. This process is the same no matter which method you use to return an ActionForward.
 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill. There's no problem when I use this to return actionforward:

return mapping.findForward("success");


But using this doesn't render the proper error messages.

return new ActionForward("/merchant.jsp?id="+num, true);

This is the code in my jsp file that suppose to print out any error or successful message:

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with the second parameter of the ActionForward constructor. If you specify true for this parameter, that means that the sendRedirect() method will be called on the HTTPServletResponse object. When this happens, a new request is generated, meaning any objects associated with the old request, including error messages are now out of scope. You can fix this either by specifying false for this parameter, or by calling the saveErrors(session, errors) method, which puts the errors in the HTTPSession rather than the request.
 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It did work. For the sake who may get in this trouble this is what i did exactly:

 
Swathi Sri
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. That helps!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic