aspose file tools*
The moose likes Struts and the fly likes Resetting response in action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Resetting response in action class" Watch "Resetting response in action class" New topic
Author

Resetting response in action class

sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi all

I have a weird problem facing in my application . When I click a button an operation is performed which takes some time. in the mean while I need to show the user some sign that the process is still going on.Hence what I had done in my action class is

PrintWriter out=response.getWriter();
out.println("Processing............");
out.flush();
try
{
// perform the operation
}
return mapping.findForward(�success�);
I am showing him Processing�.. by using response .but as soon as the operation is done I want to show my page ���.how can I get back the response object so that in the same window I should show my new page by removing that Processing�..

Any other idea in this regard is also okay
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

What I think you'll have to do is this:

Send the user to a jsp that waits a couple seconds and then submits to an AreWeThereYetAction. That action forwards back to that jsp again if the processing is not finished.

Basically you'll turn the browser into a child during a long road trip.


A good workman is known by his tools.
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
HI marc

Thats fine i will send to a jsp and then to action but how will i get to know in the action about the status of the operation ( i dont even have something like insatnce variable where i can check at the beginning of the action itself)

How can i do this ??
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Well, let's make the "AreWeThereYetAction" be the same action that performs the operation.

operationInProgress is a flag set in session
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi marc

But will this handle the concurrency issues.I mean if the user once is performing the operation and in the mean while another request comes wont this session variable create concurrency issues r will tomcat handle this ???
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

There is still a small window for one to slip in.

It might be wise to swap these to close that gap:
perform operation
set operationInProgress to true

so that you set the value to true before beginning the operation. There is still a VERY small window between checking and setting the flag but the odds of a user submitting two requests that fast AND the processor to multithread the two requests in such a way that the flag is checked in the one and then immediately the other before the first one sets the flag... not much to worry about
[ September 15, 2004: Message edited by: Marc Peabody ]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
232

Keep in mind that this flag is in the user's session. So the user would have to submit another request for procession while he/she is looking at your in-progress screen.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi marc

The above wont be a feasible solution i feel.because i need to invoke the req after some int while showing the progress screen and making another request will go the action and check for the status.in the mean while how will u make that operation running in the back ground.....its not that it will be executing for the time we will be showing him that screen


hope u got what i am saying
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

True.

Ok...
1)The first action submits the data but does not perform the operation.
2)This action forwards to the "In Progress" jsp which refreshes at 0 seconds to hit the action that performs the operation.

This way you get to see that you are supposed to wait. The operationInProgress flag would still be a good idea to prevent double submissions though. I would also set a flag by the first action readyToPerformOperation to prevent browser back button garbage.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resetting response in action class