Displaying date Into the Servlet

Displaying date Into the Servlet

Posted in : Servlet Posted on : October 30, 2010 at 6:07 PM Comments : [ 0 ]

In this tutorial you will learn how to dispaly date in servlet

Displaying Date In The Servlet

To display date into the servlet you need to import java.util.Date() class.


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletDateExample extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws 

PrintWriter out=response.getWriter();
Date date=new Date();
out.println("<Body bgcolor=green>");
out.print("<H1> Today - " +date.toString()+"</H1>");
Now add the following mapping code in your web.xml file

<!-- servlet mapping -->

When you run this application it will display message as shown below:


Download this example code

Go to Topic «PreviousHomeNext»

Your Comment:

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

Tutorial Topics