package sample; import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; public class SessionServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 8665155529222867738L; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map sessions = new HashMap(); // ContentType??? response.setContentType("text/html; charset=UTF-8"); // ?o??pPrintWriter??? PrintWriter out = response.getWriter(); // ?o? out.println(""); out.println(""); out.println("Session Test"); out.println(""); out.println(""); out.println("

Session Test of Servlet

"); out.println("
"); out.println("

Cookies

"); if(request.getCookies() != null) { for(Cookie cookie : request.getCookies()) { out.println(cookie.getName() + " = " + cookie.getValue()); out.println("
"); } } out.println("
"); out.println("

Create Sessions

"); for(int i = 1 ; i <= 10 ; ++i) { HttpSession session = request.getSession(); Integer count = sessions.get(session.getId()); if(count == null) { sessions.put(session.getId(), 1); } else { sessions.put(session.getId(), count.intValue()+1); } out.println( i + " : " + session.getId()); out.println("
"); session.invalidate(); } out.println("
"); out.println("

Result

"); out.println(""); out.println(""); for(Map.Entry entry : sessions.entrySet()){ out.println(""); } out.println("
Session IdCount
"+ entry.getKey() +"" + entry.getValue() + "
"); out.println(""); out.println(""); } }