Servlet - Auto Page Refresh Last Updated : 13 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The public service(HttpServletRequest req, HttpServletResponse res) method in the servlet component should extend HttpServlet (AC). It allows the browser to refresh the web page when a certain amount of time has passed. Auto-refresh can be enabled in two ways: setHeader(“refresh”, String “<time-in-second>”)setIntHeader(“refresh”, int <time-in-second>) "refresh" is fixed in these approaches. Time is passed to the setHeader() method as a string, while time is passed to the setIntHeader() method as an int number. The time should be expressed as a fraction of a second. Example: setIntHeader("Refresh", 5);Auto Page Refresh Example This is the PageRefresh.java file where we have written page refresh logic code Java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class PageRefresh extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set refresh time as 1 seconds response.setIntHeader("Refresh", 5); // Set response content type response.setContentType("text/html"); // Get current time Calendar calendar = new GregorianCalendar(); String am_pm; int hour = calendar.get(Calendar.HOUR); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); if(calendar.get(Calendar.AM_PM) == 0) { am_pm = "AM"; } else { am_pm = "PM"; } String CT = hour+":"+ minute +":"+ second +" "+ am_pm; PrintWriter out = response.getWriter(); out.println("<h1 align='center'>Auto Refresh Page</h1>"); out.println("<h2 align='center'>Current time: "+CT+"</h2>"); } // Handle POST method request. public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } Following is the web.xml file: XML <web-app> <servlet> <servlet-name>PageRefresh</servlet-name> <servlet-class>PageRefresh</servlet-class> </servlet> <servlet-mapping> <servlet-name>PageRefresh</servlet-name> <url-pattern>/PageRefresh</url-pattern> </servlet-mapping> </web-app> Output: It refreshes the browser every five seconds and the current time will be changed automatically. Comment More infoAdvertise with us Next Article jQuery Mobile Selectmenu refresh() Method S sanketnagare Follow Improve Article Tags : Java java-servlet Practice Tags : Java Similar Reads Servlet - Page Redirection Programming for a website is an art. To provide the view in an eminent manner, numerous steps are getting taken. Usually, a client(A simple JSP page) provides a request to a web server or app server and they process the request and provide the response. Sometimes, it happens that in order to load ba 4 min read jQuery Mobile Selectmenu refresh() Method jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be using the jQuery Mobile Selectmenu refresh() method. This will parse the original element and re-renders the menu. Syntax: $( "selector" 1 min read How to Refresh a Page using jQuery? Refreshing a page using jQuery allows you to programmatically reload the current webpage, ensuring updated content or resetting the page's state. It can be done using location.reload() method.Table of ContentUsing location.reload() MethodUsing history.go(0)Using location.replace() with Current PageR 3 min read How to Refresh a Page using jQuery? Refreshing a page using jQuery allows you to programmatically reload the current webpage, ensuring updated content or resetting the page's state. It can be done using location.reload() method.Table of ContentUsing location.reload() MethodUsing history.go(0)Using location.replace() with Current PageR 3 min read Servlet - Hits Counter Sometimes, you'll want to know the overall number of visitors to a specific page on your website. Because the life cycle of a servlet is governed by the container in which it runs, counting these hits with a servlet is fairly straightforward. The following steps are based on the implementation of a 4 min read Servlet - Fetching Result Servlet is a simple java program that runs on the server and is capable to handle requests from the client and generate dynamic responses for the client. How to Fetch a Result in Servlet? It is depicted below stepwise as shown below as follows: You can fetch a result of an HTML form inside a Servlet 3 min read Like