Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timed Redirect

 
Pearlo Muthukumaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to make a redirection from the current page (response.write of servlet) to a different servlet after a fixed time has elapsed? I am not supposed to use meta tag. May be i can use a timer for implementing this.
But no samples are avilable with a timer used within servlet code.
Hope I am clear to the willing responder.
Rgds
Muthu
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK if you can't use the meta tag (I'm assuming this is a homework assignment with such a parameter), the only other real choice is a JavaScript timeout. What you are trying to accomplish must be performed with client-side mechanisms since once the page is sent to the browser, servlets and JSP are out of the picture.
Check out the setTimeout() method on the window object.
hth,
bear
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about using the setHeader method of the response object. For example, the following will load google's home page after 10 seconds.
response.setHeader("Refresh", "10; URL=http://www.google.com")
Just make the URL the location of your servlet and change the time to whatever you want.
[ April 09, 2003: Message edited by: Bosun Bello ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.setHeader("Refresh", "10; URL=http://www.google.com")

I figured that was "off limits" since that's essentailly what the meta tag does... but I guess it'd all be up to how the assignment is worded.
Good call, Bosun!
bear
 
Pearlo Muthukumaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But will this not lead to a network roundtrip?
In my case, luckily the "redirected" servlet is also in the same server as that of "redirecting" servlet. Is there any way I could use a RequestDispatcher with the functionality (timed redirection)?
Rgds
Muthu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic