Servlet Java Tutorial

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.text.DateFormat;
public class MyServlet extends HttpServlet {
   
 public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
        
        response.setContentType("text/html");
        java.io.PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        Date creationTime = new Date(session.getCreationTime() );
        Date lastAccessed = new Date(session.getLastAccessedTime());
        Date now = new Date();
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);
        
        out.println("");
        out.println("");
        out.println("Displaying the Session Creation and Last-Accessed Time");
        out.println("");
        out.println("");
        out.println("

Session Creation and Last-Accessed Time

");
        out.println("The time and date now is: " + formatter.format(now) + "

");
        out.println("The session creation time: HttpSession.getCreationTime( ): " + formatter.format(creationTime) + "

");
        out.println("The last time the session was accessed: HttpSession.getLastAccessedTime( ): " + formatter.format(lastAccessed) );
        out.println("");
        out.println("");
        
    }
}


    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

    MyServletName
             MyServlet
             
    

    
    MyServletName
        /index.html