{"id":10181,"date":"2015-08-21T03:13:39","date_gmt":"2015-08-21T07:13:39","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10181"},"modified":"2015-08-01T09:19:25","modified_gmt":"2015-08-01T13:19:25","slug":"showsession-java-servlet-that-uses-session-tracking-to-determine-if-the-client-is-a-repeat-visitor-uses-the-servletutilities-class-to-simplify-the-doctype-and-head-output","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10181","title":{"rendered":"ShowSession.java Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output."},"content":{"rendered":"<pre>ShowSession.java  Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities  class to simplify the DOCTYPE and HEAD output.\r\n\r\n\r\npackage cwp;\r\n\r\nimport java.io.*;\r\nimport javax.servlet.*;\r\nimport javax.servlet.http.*;\r\nimport java.net.*;\r\nimport java.util.*;\r\n\r\n\/** Simple example of session tracking.\r\n *<\/pre>\n<p>* Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May be freely used or adapted. *\/ public class ShowSession extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(&#8220;text\/html&#8221;); PrintWriter out = response.getWriter(); String title = &#8220;Session Tracking Example&#8221;; HttpSession session = request.getSession(true); String heading; Integer accessCount = (Integer)session.getAttribute(&#8220;accessCount&#8221;); if (accessCount == null) { accessCount = new Integer(0); heading = &#8220;Welcome, Newcomer&#8221;; } else { heading = &#8220;Welcome Back&#8221;; accessCount = new Integer(accessCount.intValue() + 1); } \/\/ Use setAttribute instead of putValue in version 2.2. session.setAttribute(&#8220;accessCount&#8221;, accessCount); out.println(ServletUtilities.headWithTitle(title) + &#8220;\\n&#8221; + &#8221;<\/p>\n<h1 align=\"\\&quot;CENTER\\&quot;\">&#8221; + heading + &#8220;<\/h1>\n<pre>\\n\" +\r\n                \"<\/pre>\n<h2>Information on Your Session:<\/h2>\n<pre>\\n\" +\r\n                \"\\n\" +\r\n                \"\\n\" +\r\n                \"  \\n\" +\r\n                \"  \\n\" +\r\n                \"  \\n\" +\r\n                \"  \\n\" +\r\n                \"<\/pre>\n<table border=\"1\" align=\"\\&quot;CENTER\\&quot;\">\n<tbody>\n<tr bgcolor=\"\\&quot;#FFAD00\\&quot;\">\n<th>Info Type<\/th>\n<th>Value\\n&#8221; + &#8220;<\/th>\n<\/tr>\n<tr>\n<td>ID\\n&#8221; + &#8220;<\/td>\n<td>&#8221; + session.getId() + &#8220;\\n&#8221; + &#8220;<\/td>\n<\/tr>\n<tr>\n<td>Creation Time\\n&#8221; + &#8220;<\/td>\n<td>&#8221; + new Date(session.getCreationTime()) + &#8220;\\n&#8221; + &#8220;<\/td>\n<\/tr>\n<tr>\n<td>Time of Last Access\\n&#8221; + &#8220;<\/td>\n<td>&#8221; + new Date(session.getLastAccessedTime()) + &#8220;\\n&#8221; + &#8220;<\/td>\n<\/tr>\n<tr>\n<td>Number of Previous Accesses\\n&#8221; + &#8220;<\/td>\n<td>&#8221; + accessCount + &#8220;\\n&#8221; + &#8220;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre>\\n\" +\r\n                \"\");\r\n\r\n  }\r\n\r\n  \/** Handle GET and POST requests identically. *\/\r\n\r\n  public void doPost(HttpServletRequest request,\r\n                     HttpServletResponse response)\r\n      throws ServletException, IOException {\r\n    doGet(request, response);\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ShowSession.java Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.util.*; \/** Simple example of session tracking. * * Taken from Core Web Programming Java 2 Edition * &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10181\">Continue reading<\/a><\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1417,1424],"tags":[706,308,1461,285],"class_list":["post-10181","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-servle","tag-285","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":26555,"url":"http:\/\/bangla.sitestree.com\/?p=26555","url_meta":{"origin":10181,"position":0},"title":"ShowSession.java  Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities  class to simplify the DOCTYPE and HEAD output. #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 28, 2021","format":false,"excerpt":"ShowSession.java Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.util.*; \/** Simple example of session tracking. * * Taken from Core Web\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10175,"url":"http:\/\/bangla.sitestree.com\/?p=10175","url_meta":{"origin":10181,"position":1},"title":"SetCookies.java Servlet that sets a few persistent and session cookies. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output.","author":"","date":"August 19, 2015","format":false,"excerpt":"SetCookies.java\u00a0 Servlet that sets a few persistent and session cookies. Uses the ServletUtilities\u00a0 class to simplify the DOCTYPE and HEAD output. \u00a0 package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; \/** Sets six cookies: three that apply only to the current \u00a0*\u00a0 session (regardless of how long that session lasts)\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10168,"url":"http:\/\/bangla.sitestree.com\/?p=10168","url_meta":{"origin":10181,"position":2},"title":"EncodedPage.java Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output.","author":"","date":"August 18, 2015","format":false,"excerpt":"EncodedPage.java\u00a0 Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities\u00a0 class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.zip.*; \/** Example showing benefits of gzipping pages to browsers \u00a0*\u00a0 that can handle\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26533,"url":"http:\/\/bangla.sitestree.com\/?p=26533","url_meta":{"origin":10181,"position":3},"title":"EncodedPage.java  Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities  class to simplify the DOCTYPE and HEAD output. #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 27, 2021","format":false,"excerpt":"EncodedPage.java Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.zip.*; \/** Example showing benefits of gzipping pages to browsers * that can handle\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10158,"url":"http:\/\/bangla.sitestree.com\/?p=10158","url_meta":{"origin":10181,"position":4},"title":"SimplerHelloWWW.java Servlet that uses ServletUtilities to simplify the generation of the DOCTYPE and HEAD part of the servlet.","author":"","date":"August 15, 2015","format":false,"excerpt":"SimplerHelloWWW.java\u00a0 Servlet that uses ServletUtilities\u00a0 to simplify the generation of the DOCTYPE and HEAD part of the servlet. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; \/** Simple servlet that generates HTML. This variation of \u00a0*\u00a0 HelloWWW uses the ServletUtilities utility class \u00a0*\u00a0 to generate the DOCTYPE, HEAD, and TITLE.\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26549,"url":"http:\/\/bangla.sitestree.com\/?p=26549","url_meta":{"origin":10181,"position":5},"title":"SetCookies.java  Servlet that sets a few persistent and session cookies. Uses the ServletUtilities  class to simplify the DOCTYPE and HEAD output. #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 28, 2021","format":false,"excerpt":"SetCookies.java Servlet that sets a few persistent and session cookies. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; \/** Sets six cookies: three that apply only to the current * session (regardless of how long that session lasts) *\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10181"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10181\/revisions"}],"predecessor-version":[{"id":10182,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10181\/revisions\/10182"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10181"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}