Solved

JSP (page direction) problem.

Posted on 2002-03-12
12
456 Views
Last Modified: 2008-03-10
Hi,
First, my set-up is.. weblogic, ejb backend, jsp front end, with a servlet brokering requests.

My problem is that I need to execute some serverside work, as a result of a POST request, that can take up to 2 hours to complete (legacy system). Therefore the browser times out b4 it's completed......

In "pseudocode" what I (the servlet) need to do is...

* recieve and handle POST request
* display a re-freshing "please wait" page/jsp to avoid
  the browser timing out the request.
* execute the work that can take hours.
* redirect to "finished" page & display details.

The main difficultly is that you seem to be only able to call HttpServletResponse::sendRedirect() *once*, it says so in the docs.

So I call it once to display the "please wait" page, but then can't call it again to show the "finished" page.

But also, weblogic seems to ignore my request to display the "please wait" page until *after* the 2-hour long method executes! I've tried flushing the buffers but it doesn't help.

any suggestions greatly appreciated!
thanks,
sd

0
Comment
Question by:somadude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +5
12 Comments
 

Expert Comment

by:ph0rman
ID: 6857181
One possibility would be to use javascript to create a new window just before the submit is processed.  the new window would display the "please wait" and could do refreshing to avoid timeouts.  Once the initial window is finished processing it can close that secondary window via javascript.  The down-side is that you end up with two windows rather than one.

You could also do some shenanigans using frames and create the same type of behavior if keeping it one window is important.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6857280
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6857326
use thread, something like this:

public class BackgroundProcessorServlet extends HttpServlet implements Runnable {

     private static final int NOT_WORKING = 0;    
     private static final int WORKING = 1;

     Thread runner; // this is the thread that does the work
     int status;
     String strStatus;
     
     public void init(ServletConfig config) throws ServletException
     {
          super.init(config);
     
          status = NOT_WORKING;
          strStatus = "Not working";
     }


     public void doGet(HttpServletRequest req, HttpServletResponse res)
                         throws ServletException, IOException {

          res.setContentType("text/html");
          PrintWriter out = res.getWriter();

          if (status != WORKING) {
               runner = new Thread(this);
               runner.setPriority(Thread.MIN_PRIORITY); // be nice ;)
               runner.start();

               strStatus = "Working";
               status = WORKING;
          }
         
          out.println(strStatus);
          return;
     }



     public void doPost(HttpServletRequest req, HttpServletResponse res)
                         throws ServletException, IOException {
          doGet(req,res);
          return;
     }    

     public void run() {

          // make the thread do whatever you need it to do

          // when your done, set strStatus and status back to not working
     }

}    


0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 86

Expert Comment

by:CEHJ
ID: 6858704
Don't know if this would work, but you could try to add this to your headers of your 'wait' screen.
<META HTTP-EQUIV=Refresh CONTENT="180; URL=http://www.your-wait-page.jsp/"> This *should* cause is to refresh every three minutes in your browser. You could maybe then get the servlet to check a variable and redirect when the data is available, otherwise simply return.
0
 
LVL 1

Expert Comment

by:gigsvoo
ID: 6859164
Look at this website:

http://www.jdance.com
0
 

Author Comment

by:somadude
ID: 6859997
CEHJ - I actually tried a something almost exactly like that a few days ago. What I did was..

* redirect to wait page
* continue processing
* wait-page checks flag in session to see if processing is
  finished, if finished, redirect to finish-page.
* processing is finished, flag is set in session

I thought this was going to work, but there are 2 problems

1) you can only call response.sendRedirect once
2) alot of the time, weblogic won't even display the
   wait-page until the server-side processing is
   finished. ??
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6860016
As far as the problems are concerned:

1) Surely you only need to redirect once per page - once to the 'wait' page, then once to the 'finished' page (redirected *by* the wait page)?

2) You are doing the processing in another thread aren't you?

Of course, you really need messaging paradigms for this sort of thing...
0
 
LVL 3

Accepted Solution

by:
saxaboo earned 200 total points
ID: 6860119
Hi,

having faced this problem a number of times, I'm truly convinced that the solution is not such or such technical trick.
The real question is : do you really need synchronous processing ?

Imagine one of you users posting data to your app, which sends it to your back-end and manages to somewhat make the browser "wait" for the response. Your user is very unlikely to wait for the response doing nothing but looking at the browser screen. He or she will probably return back to Word or PowerPoint to do something else, maybe have a coffee break, and maybe every 15 minutes he or she will Alt-tab to IE to see if the result is here.

My point is : even if your system is synchronous, your end-user is probably not. I may be mistaken but the question is worth asking.

A more "conventional" solution would therefore be to launch the task as an asynchronous process, by starting a thread like bobbit31 suggested (better : use a Message-driven bean !), or using a MOM like MQSeries, and immediately returning a page saying "Your request is being processed. Check out <a href="/results_received.jsp">this page</a> for results every 2 hours or so !"

When you task completes, it writes something somewhere in your local DB (or in a file, or whatever ...) saying "the request submitted by user 'chandler' returned the following results : blah blah ...."

And your results_received.jsp questions your DB to check if any results have been received from the back-end.

As a conclusion, I suggest you to work on the functional side first

-S
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6860147
I'd go along with Saxaboo on this one, as the last line of my previous message suggests.

You could even implement a quick and dirty email solution!
0
 

Author Comment

by:somadude
ID: 6861134
saxaboo - yeah I agree with you, I actually started checking out JMS this morning, looks like it could be the ticket.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7901842
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: saxaboo
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7962606
Per recommendation, force-accepted.

Netminder
EE Admin
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pagenation logic how it is working in my code 1 82
Java syntax, or is it Selenium 6 64
passing enum to a method 4 52
Website checklist for browser compatibility? 2 57
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question