Home Servlets Time Updater in Servlet



Time Updater in Servlet
Posted on: March 12, 2008 at 12:00 AM
In this program we are going to make one program on servlet which will keep on updating the time in every second and the result will be displayed to you.

Time Updater in Servlet

     

In this program we are going to make one program on servlet which will keep on updating the time in every second and the result will be displayed to you. 

To make this servlet firstly we need to make a class named TimeUpdater.  The name of the class should be such that it becomes easy to understand what the program is going to do. Call the method getWriter() method of the response object which will return a PrintWriter object. Use the method getHeader() of the response object to add a new header. We can also use setHeader() in place of getHeader(). The setHeader() method overrides the previous set header. Now by using the PrintWriter object display the result on the browser.

The code of the program is given below:

 

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class TimeUpdater extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter pw = response.getWriter();

response.addHeader("Refresh", "1");
pw.println(new Date().toString());
}
}

The output of the program is given below:

Related Tags for Time Updater in Servlet:
ccomidebrowserclassstldatetimeupdateobjectioservletheadermakemethodprintgetdisplayoverridevinewnamereturnusingintthisidresponsesetwriterowrowscalladdprogramtoramwseldupdatingwssheilitdeslscanspluseulresultimfirstcebrowseinnopdacalasstamheadntplaycaddletjispadaceclesallovernamedmeobjprodowhichwritersurntheadsuspsoeeespetwatkisirhaimellpreoverridesgoeaandarrvupdtwssrithshocondstatihatdispeueulsojeplprprintwriterndonomogro


More Tutorials from this section

Ask Questions?    Discuss: Time Updater in Servlet   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.