Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting view to a a jsp page from a self refeshing page  RSS feed

 
Deepal Udeshi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am facing a small problem while setting the view to a jsp page from a self refeshing page

We have a jsp page say first.jsp. On a click of a button it calls a class (say complex.class) that does some processing. After the processing is complete the complex class sets a Flag to true. and sets the view to second.jsp.

The processing is very complex and takes a lot of time to complete, so we need to show a progress page say progress.jsp to the user.
The progress.jsp is a self refreshing page, It calls its command class and checks a flag.
If the flag is false the view is set back to the progress.jsp.

The problem we face is that since there are two threads (1. to progress.jsp and 2. complex.class ) running simultaneously, and the view is set by both the threads, the required view is not set and the code breaks.

Please let me know a way to set the view.
Thanks
Deepal
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The process that does the complex work should not set the view. It should do the work and set a session variable that indicates process completion (percent done, or flag, or whatever). It should not care about the display.

When the process is kicked off, you forward to a Servlet which checks the status of the complex work via the session variable. If the work isn't done it forwards to the progress bar page which doesn't refresh to itself, but instead refreshes to the Servlet.

If the work is done the Servlet forwards to finished page.

That way the worker just cares about the work, the progress page just cares about displaying the proper progress, and the Servlet makes sure things go where they should go.
 
Deepal Udeshi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for the reply.
But we are now facing another problem. The complex processing is done and is saved in its request scope.

When the progress page has to set the progress, it does not get the objects that were created by the complex processsing.
Hence the data can not be shared between the two processes.

Can you please suggest a way to do that?

Thanks
Deepal
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest thing to do is to save the results in the session scope, but that isn't very scalable. Another option is to store the results in a database and store an ID for retrieving the results in the session.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!