• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Forwarding from form or action

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you, Merrill. That works!
     
    reply
      Bookmark Topic Watch Topic
    • New Topic