Java code to refresh browser
-
14-03-2021 - |
Question
Whenever a user logs in(into an app which I've been working on), he will be redirected to his home page, which needs to be refreshed one time. I have to write the code in .java file to basically refresh the browser.
How can this be achieved with java. I know it can be done using javascript, but I have to achieve the above in a .java file. Any ideas ???
Solution
Just use code like this:
response.setHeader("Refresh", "0; URL=http://your-current-page");
OTHER TIPS
response.setHeader("Refresh", "0; URL=" + request.getContextPath() + "/test.do?methodname=test¶m=test");
Instaed of hardcoding the URL(URL=http://your-current-page). you can use below.
request.getContextPath() will get respective ip address
You want to set a cookie that will cause a page refresh.
For Java use this: http://www.rgagnon.com/javadetails/java-0180.html
For the homepage JavaScript use http://techpatterns.com/downloads/javascript_cookies.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow