@WebServlet(name="SessionTimeoutCheck", urlPatterns={"/SessionTimeoutCheck"})
public class SessionTimeoutCheckServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("Current session ID: " + session.getId());
out.write("<br />\n");
out.write("Requested session ID " + request.getRequestedSessionId());
out.write("<br />\n");
if (request.getRequestedSessionId() != null) {
if (request.isRequestedSessionIdValid()) {
out.write("Valid session");
} else {
out.write("Session expired");
}
} else {
out.write("No sessionId specified => new session");
}
}
}