Welcome to Kode Java

Kode Java website provides beginners to Java programming some examples to use the Java API (Application Programming Interface) to develop applications. Learning from some examples will hopefully decrease the time required to learn Java.

In this website you will find a lot of examples which grouped by the Java API package. You can easily find a solution to your problem. Enjoy your study, come and visit the site regularly to find more and more examples of Java code.

--
I Wayan Saryada
Kode Java Webmaster

Java programmers recommend using Java Hosting for your scripts and JSP based websites to reach the full potential of your site and not experience any errors.

How do I know session last access time?

package org.kodejava.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

public class SessionLastAccessTime extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession();
        Date date = new Date(session.getLastAccessedTime());

        PrintWriter writer = response.getWriter();
        writer.println("Last accessed time: " + date);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
}

This servlet will return a result like:

Last accessed time: Thu Jan 03 00:47:34 ICT 2008
Java Training

Sponsored Links

Our Friends