Servlet Program to Print Today’s Date and Time using refresh header

Simple Java Servlet Program to Print Date and Time using refresh header (Time updates automatically)

Code:

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.util.Date;

public class servlet2 extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse rsp)

throws ServletException, IOException {

rsp.setIntHeader("Refresh", 1);

rsp.setContentType("text/html");

PrintWriter out = rsp.getWriter();

Date now = new Date();

out.println("<html>");

out.println("<head><title> Time Check </title></head>");

out.println("<body>");

out.println("<p text-align=auto>Current Time: " + now + "</p>");

out.println("</body></html>");

}

}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Java Program to Implement sorting algorithm using TCP on Server application

C++ program to perform data transformation Min-max and Z score Normalization