Servlets Auto Page Refresh - Java Servlets

What is Servlets Auto Page Refresh?

Consider a webpage which is displaying live game score or stock market status or currency exchange ratio. For all such type of pages, you would essential to restore your web page frequently using refresh or reload button with your browser.

Java Servlet makes this job easy by providing you a mechanism where you can make a webpage in such a way that it would refresh mechanically after a given interval.

The simplest way of refreshing a web page is using method setIntHeader()of response object. Following is the signature of this method –

This technique sends back header "Refresh" to the browser along with an integer value which indicates time interval in seconds.

Auto Page Refresh Example

This instance shows how a servlet performs auto page refresh using setIntHeader() method to set Refresh header.

Now let us compile the above servlet and create the following entries in web.xml

Currently call this servlet using URL http://localhost:8080/Refresh which would show current system time after every 5 seconds as follows. Just run the servlet and wait to see the result –

Auto Page Refresh using Servlet

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Servlets Topics