wood burning stoves 2.0*
The moose likes Servlets and the fly likes Redirecting... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Redirecting..." Watch "Redirecting..." New topic
Author

Redirecting...

Tom Diamond
Ranch Hand

Joined: May 10, 2001
Posts: 98
Hello,
Is there a smart way to redirect to another page after a specific amount of time? (2 seconds for example).
Tom.
Jared Krull
Ranch Hand

Joined: Sep 28, 2001
Posts: 32
Personally, I prefer to use good old JavaScript....
<HTML>
<HEAD>
</HEAD>
<SCRIPT>
<!-- START HIDE
function jmp(){
document.location.href="http://www.Yahoo.com/"
}
// STOP HIDE -->
</SCRIPT>
<BODY onload="setTimeout('jmp()',2000)">
</BODY>
</HTML>
That's set for 2 seconds
------------------
C programmer gone astray


C programmer gone astray
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes, you can. You need to set it in the response.setHeader()
Here is an example that loads the Google page after 20 seconds.
response.setHeader("Refresh", "20; URL=http://www.google.com")

Bosun

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Tom Diamond
Ranch Hand

Joined: May 10, 2001
Posts: 98
Thanx for your answers.
The JavaScript stuff works fine but not for my case : the redirection link is not static but it is "calculated" inside a snippet (the page that contains the redirection does some kind of proccesseing and may be called from various pages. I want to redirect the user at the page he submitted the information). As soon as I know Javascript does not "see" Java variables declared in a JSP (the calculated link is a string). I tried the following :
response.setHeader("Refresh", "2; URL=" + myLink)
but the server said :
org.apache.jasper.JasperException: Unable to compile class for JSP response.setHeader("Refresh", "2; URL=" + pageLink)
Any further ideas?
Tom.

[This message has been edited by Tom Diamond (edited October 16, 2001).]
Tom Diamond
Ranch Hand

Joined: May 10, 2001
Posts: 98
Anyone with an idea???
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Tom, if this ("Refresh", "2; URL=" + pageLink) is the exact way you had it, you are missing a closing quote. It should be
("Refresh", "2; URL=" + pageLink")

Bosun
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

actually...
("Refresh", "2; URL=\"" + pageLink + "\"")
isn't it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirecting...