Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 224
Fseee Avatar asked Feb 14 '12 21:02

Fseee


1 Answers

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"); %>.

like image 193
Oleg Mikheev Avatar answered Nov 15 '22 12:11

Oleg Mikheev