• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resetting response in action class

 
sreenath reddy
Ranch Hand
Posts: 415
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sreenath reddy
Ranch Hand
Posts: 415
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 415
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33700
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sreenath reddy
Ranch Hand
Posts: 415
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic