• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding from form or action

 
Ritu varada
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp which accepts input and the action class calls another service class which searches the database and returns a resultset. But, if the resultset is empty, I need to redisplay the input jsp page with an error message. I do not want to call the service method in the form but once I get to action class, how do I go back to input jsp with a message ? I am sorry if this is a really basic question. I am just not sure how to design this. Thanks.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the process:
  • In your Struts-config.xml, Create a local forward for this action to the input jsp.
  • In your ApplicationResources.properties file, create an entry for the message you want to display
  • In your input jsp, place the tag <html:errors/> where you want the message to appear
  • In your action class, Instantiate an object of type ActionErrors
  • If the resultSet is empty, instantiate an object of type ActionMessage, using the constructor that requires a message key. (Use the key of the message you set up in the 2nd step above)
  • Add this object to the ActionErrors using the add() method.
  • Call the saveErrors() method provided by the superclasss
  • Forward to the input JSP.


  • [ March 23, 2005: Message edited by: Merrill Higginson ]
     
    Ritu varada
    Ranch Hand
    Posts: 119
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you, Merrill. That works!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic