Fseee
Fseee

Reputation: 2631

sendRedirect after time interval avoiding javascript or php

How can I do the following

response.sendRedirect("index.jsp");

after a certain time interval from another jsp without using javascript or php?

The idea is to show an error in a "error_page.jsp" and then after some time automatically redirect the user to the index page. Thanks in advance.

Upvotes: 7

Views: 23230

Answers (1)

Oleg Mikheev
Oleg Mikheev

Reputation: 17444

Refresh HTTP header is supposed to control timed redirects.

You can set it in HTML, by adding to your error_page.jsp this meta tag:

<meta http-equiv="Refresh" content="5;url=next_page.jsp">

(5 stands for 5 seconds before next_page.jsp gets loaded)

You would most probably pass the name of the next page as a parameter to the JSP, or a request attribute, so that instead of next_page.jsp it would be ${param.nextPage} or just ${nextPage} respectively.

And of course you can set the same header from servlet: response.setHeader("Refresh", "5;url=next_page.jsp");.

You could even put this code inside JSP <% response.setHeader("Refresh", "5;url=next_page.jsp"); %>.

Upvotes: 25

Related Questions