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.
Joined: Feb 15, 2005
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