• Post Reply Bookmark Topic Watch Topic
  • New Topic

Redirect  RSS feed

 
Hui Ge
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On some websites including java ranch, there is a function whereby the web page shows that the user will be redirected to another page in a few seconds. How is this done programmatically?

I tried on a redirect.jsp
<%
Thread.sleep(30);
RequestDispatcher dis = request.getRequestDispatcher(/next.jsp);
dis.forward(request, response);
%>
but i see next.jsp straight away without seeing the contents of redirect.jsp.

Can someone gimme a clue? Thanks in advance.
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you will need to use javascript for using the redirect and the reason for this is you need the page to be loaded and then you want it to redirect.
you could write a function in javascript using the settimeout() for doing this.
look into the setTimeout() documentation and i am sure you will come up with the solution.

One thing which is wrong in your method is the timeout is at the host and the page will not load unless the timeout expires. that is when the server will respond. you may not be noticing the difference as the time you have specified is too small 30 millis.
javascript is the way to go.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You either do like below.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!