Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

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.

Ads

Tutorials   
Ads

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:

Advertisements

Ads
Share on Google+Share on Google+

Time Updater in Servlet

Posted on: March 12, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Time Updater in Servlet   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Aarish Narang
January 16, 2012
java

please help how to run servlet program in eclips

Ads

 

Ads