import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
/**
* This Servlet prints the current date and time.
*
* @author Sofoklis Stouraitis
*
*/
public class ShowDateServlet extends HttpServlet {
/**
* Handles HTTP GET requests.
*
* @param request
* the request object
* @param response
* the response object
*
* @throws IOException
* if an input or output error is detected when the servlet
* handles the GET request
* @throws ServletException
* if the request for the GET could not be handled
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html; charset=windows-1253");
PrintWriter out = new PrintWriter(response.getWriter(), true);
try {
Calendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
int hours = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
int seconds = cal.get(Calendar.SECOND);
out.println("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
out.println("<html>");
out.println("<head>");
out.println(" <title>ShowDateServlet</title>");
out.println(" <meta http-equiv='Content-Type' content='text/html; charset=windows-1253'>");
out.println("</head>");
out.println("<body>");
out.println(" <h1>ShowDateServlet is running..</h1>");
out.println(" <p>Ημερομηνία: " + day + "/" + month + "/" + year
+ "<br>");
out.println("Ώρα: " + hours + ":" + minutes + ":" + seconds
+ "</p>");
out.println(" </body>");
out.println("</html>");
} catch (Exception ex) {
out.println("Exception: " + ex.getMessage());
out.println(" </body>");
out.println("</html>");
}
}
}// End of class
|