package com.cv.servlet.session;
import java.io.IOException;
import java.io.PrintWriter;
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 org.apache.log4j.Logger;
/**
* Servlet implementation class BeerServlet
*/
public class SessionInValidate extends HttpServlet {
private static final Logger LOGGER = Logger.getLogger(SessionInValidate.class);
/**
* @see HttpServlet#HttpServlet()
*/
public SessionInValidate() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("LOGGER : SessionInValidate doGet(HttpServletRequest,HttpServletResponse)");
HttpSession session = request.getSession();
response.setContentType("text/html");
session.setAttribute("foo", "42");
PrintWriter out = response.getWriter();
System.out.println("setAttribute(\"foo\", \"42\") called...");
LOGGER.info("setAttribute(\"foo\", \"42\") called...");
// session.invalidate();
session.setMaxInactiveInterval(1);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (session.isNew()) {
out.print("This is new session...<br>");
} else {
out.print("This is old session...<br>");
}
String fooValue = (String) session.getAttribute("foo");
out.print("fooValue : : "+fooValue);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("LOGGER : SessionInValidate doPost(HttpServletRequest,HttpServletResponse)");
doGet(request, response);
}
} |
No comments:
Post a Comment