• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

response.setHeader("Refresh", "10; URL=http:\\ www.javaranch.com");

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

A basic question about the Refresh header in response.

I read in a book that a common technique to avoid response from timing out for request that take a long time to process is is to set the

response.setHeader("Refresh", "10; URL=http:\\www.javaranch.com");

So my understanding of this is, if my response takes longer than 10 secs, the client will be taken to javaranch after 10 secs.
And when my final response does get generated, it will be sent to the client.

To test this out, I wrote a small servlet which just waits for 1 minute before sending a sample response to the client. I also set the Refresh header in the response. But I don't see move to javaranch.com after 10 secs. I just get my desired response after 1 minute

So, it'll be great if anybody could suggest what is wrong with my understanding or my code !!


 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Anupreet,

This is nothing but Automatic Refreshing what you are trying to do in your servlet code, which is supported by many newer versions of Netscape Navigator and Microsoft Internet Explorer. This can also be done directly in the browser by using the <META> tag within the <HEAD> section of the document.
"Auto refreshing" means that once one page loads, you can set a certain number of seconds and then the browser will load another page automatically. The basic structure is as follows:
<meta http-equiv=REFRESH CONTENT="x_seconds; url = http://www.yourhost.com/pagetosendto.html">

You can also specify this via setHeader("Refresh", "x_seconds; url = http://www.yourhost.com/pagetosendto.html") in servlets.
It means "reload this page or go to the specified URL in x_seconds seconds." It does not mean "reload this page or go to the specified URL every x_seconds seconds."

In your case, since the servlet hasn't generated/loaded the HTML page completely, the www.javaranch.com site is not launched and when once the page is generated after waiting for 1 minute (which you have specified in your code), you have to wait for another 10secs to load this site after the page gets loaded.

Hope this explanation is clear...
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anupreet Arora:


Style note: don't go catching Throwables - there be dragons! You'll probably get a stack trace from your servlet container if things go bang in here during development. I would recommend only catching checked exceptions that aren't thrown by the doGet method. By catching Throwable you're catching Error as well as Exception which is something you would need to have a very good reason to do.

Jules
 
Anupreet Arora
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the wonderful explanation.. and by and large my understanding of the issue seems to be in sync with what your explanation is.

But I was reading this book by Faulkner, and came across this passage


Another response header technique that is uncommon but helpful is to send a wait page or a page that will auto-refresh to a new page after a given period of time. This tactic is helpful in any case where a response might take an uncontrollable time to generate, or for cases where you want to ensure a brief pause in a response. The entire mechanism revolves around setting the Refresh response header25. The header can be set using the following:

response.setHeader("Refresh", "time; URL=url" );

Where "time" is replaced with the amount of seconds, the page should wait, and "url" is replaced with the URL that the page should eventually load.



What is not clear to me in this is how is this useful in cases where a response might take an uncontrollable time to generate? In context of my example above, I don't want to go to javaranch.com after I have waited for 1 minute and another 10 secs. I want to go to javaranch after 10 secs while my response is taking one minute (read an uncontrollable time) to generate.

Appreciate your help ..
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to refresh my jsp after sending a file for download.
For this I've used this:

response.setHeader("Refresh", "time; URL=url" );

In mozilla is working perfectly but in ie it doesn't do a thing. Does anyone know anything about this problem?
Thank you in advance.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have done web designing then you may find that most of the time,
it happend things working on mozilla doesnot works on IE,As here also we are setting the header which is bascially identified by the browser which only display this,
So may be the syntax which you are usiing is having some error which mozialla ignores but IE detects that so not showing your page.

So please check the syntax properly..
 
manuela marginean
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shanky Sohar wrote:If you have done web designing then you may find that most of the time,
it happend things working on mozilla doesnot works on IE,As here also we are setting the header which is bascially identified by the browser which only display this,
So may be the syntax which you are usiing is having some error which mozialla ignores but IE detects that so not showing your page.

So please check the syntax properly..



Thank you for your quick response.
Yes, I know that ie mostly doesn't work, but I really need to solve this problem.
Regarding my syntax, where could have I done wrong in this simple code:




This is the latest version, cause I've tried them all.

I forgot to mention that this works fine if I don't send a file for download from servlet to jsp.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anupreet Arora wrote:Hi,

What is not clear to me in this is how is this useful in cases where a response might take an uncontrollable time to generate? In context of my example above, I don't want to go to javaranch.com after I have waited for 1 minute and another 10 secs. I want to go to javaranch after 10 secs while my response is taking one minute (read an uncontrollable time) to generate.

Appreciate your help ..



The way I have seen this mechanism used in practice most of the time is a scenario where 3 "pages" are involved. The 1st page - your input form. 2nd page - a "please wait while we process your request" page. 3rd page - the response "we're done, here's you answer" page. The input form actually submits not to the intended processing target action/servlet but to the wait page passing along all user entered data. The wait page usually has some animated equivalent of a spinning hourglass or progress meter of some kind. As soon as the wait page loads, it automatically uses the "Refresh" mechanism with a wait period of about 1 second to invoke the actual request processing servlet, again passing along all the user entered data from the first input page. Now the user continually sees the "wait" page whilst the long running request is processing on the backend. When the servlet is done it sends the 3rd page as the response. In essence the wait page is nothing but an intermdiary proxy to the actual form processing servlet so that the user gets the visual cue that something is happening on the backend and they are not as likely to want to hit refresh or something.
 
Whatever. Here's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic