This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Returning a javascript success message from action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Returning a javascript success message from action class" Watch "Returning a javascript success message from action class" New topic
Author

Returning a javascript success message from action class

Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Hello,

I am trying to make a struts (version <2) app, and am inserting an employee record.
All I want to do is to a) display an alert saying employee created (and clear out the emp details fields) b) validation for the emp details (which I plan to do in the validate method).
Any and every example I search, all of them are returning a success or a failure from the action class, in terms of a new jsp.

I could definitely redirect to the same jsp and have an if/else block and check for some flag I can set in the session. But, is this the only way to go about it ?
What could I do ?

cheers,
Jaimesh M Ponkia
Greenhorn

Joined: Nov 24, 2010
Posts: 21
You can use Ajax to insert the record to database and return true/false based on the insert status.

Other way is to keep a variable in your bean class and set it based on the result of the insert status and once the same jsp is reloaded, call a method on load of the page where in you can check the status of that hidden variable and display alert and clear out the fields. This is the same method which you described in your post.

These are the only 2 ways that come to mind right now.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Returning a javascript success message from action class
 
Similar Threads
persistence.xml file for MS SQL Server 2000
How to get Arraylist in jsp page to render
Cannot create iterator for FormBean
jsp:useBean type is not working?
Struts 2 error