{"id":26533,"date":"2021-04-27T23:10:05","date_gmt":"2021-04-28T03:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/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-c\/"},"modified":"2021-04-27T23:10:05","modified_gmt":"2021-04-28T03:10:05","slug":"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-c","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26533","title":{"rendered":"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"},"content":{"rendered":"<pre>\nEncodedPage.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. \n\npackage cwp;\n\nimport java.io.*;\nimport javax.servlet.*;\nimport javax.servlet.http.*;\nimport java.util.zip.*;\n\n\/** Example showing benefits of gzipping pages to browsers\n *  that can handle gzip.\n *  <p>\n *  Taken from Core Web Programming Java 2 Edition\n *  from Prentice Hall and Sun Microsystems Press,\n *  .\n *  May be freely used or adapted.\n *\/\n\npublic class EncodedPage extends HttpServlet {\n  public void doGet(HttpServletRequest request,\n                    HttpServletResponse response)\n      throws ServletException, IOException {\n    response.setContentType(&quot;text\/html&quot;);\n    String encodings = request.getHeader(&quot;Accept-Encoding&quot;);\n    String encodeFlag = request.getParameter(&quot;encoding&quot;);\n    PrintWriter out;\n    String title;\n    if ((encodings != null) &amp;&amp;\n        (encodings.indexOf(&quot;gzip&quot;) != -1) &amp;&amp;\n        !&quot;none&quot;.equals(encodeFlag)) {\n      title = &quot;Page Encoded with GZip&quot;;\n      OutputStream out1 = response.getOutputStream();\n      out = new PrintWriter(new GZIPOutputStream(out1), false);\n      response.setHeader(&quot;Content-Encoding&quot;, &quot;gzip&quot;);\n    } else {\n      title = &quot;Unencoded Page&quot;;\n      out = response.getWriter();\n    }\n    out.println(ServletUtilities.headWithTitle(title) +\n                &quot;n&quot; +\n                &quot;<h1 ALIGN=\"&quot;CENTER&quot;\">&quot; + title + &quot;<\/h1>n&quot;);\n    String line = &quot;Blah, blah, blah, blah, blah. &quot; +\n                  &quot;Yadda, yadda, yadda, yadda.&quot;;\n    for(int i=0; i&lt;10000; i++) {\n      out.println(line);\n    }\n    out.println(&quot;&quot;);\n    out.close();\n  }\n}\n\n\n\n<\/p><\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10249<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Servlet<br \/>Tags:Java\/J2EE\/J2MEServlet<br \/> Post Data:2017-01-02 16:04:28<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 gzip. * * Taken from &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26533\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-26533","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10168,"url":"http:\/\/bangla.sitestree.com\/?p=10168","url_meta":{"origin":26533,"position":0},"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":10181,"url":"http:\/\/bangla.sitestree.com\/?p=10181","url_meta":{"origin":26533,"position":1},"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.","author":"","date":"August 21, 2015","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;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":10158,"url":"http:\/\/bangla.sitestree.com\/?p=10158","url_meta":{"origin":26533,"position":2},"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":26555,"url":"http:\/\/bangla.sitestree.com\/?p=26555","url_meta":{"origin":26533,"position":3},"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":26533,"position":4},"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":26523,"url":"http:\/\/bangla.sitestree.com\/?p=26523","url_meta":{"origin":26533,"position":5},"title":"SimplerHelloWWW.java  Servlet that uses ServletUtilities  to simplify the generation of the DOCTYPE and HEAD part of the servlet. #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 27, 2021","format":false,"excerpt":"SimplerHelloWWW.java Servlet that uses ServletUtilities 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 * HelloWWW uses the ServletUtilities utility class * to generate the DOCTYPE, HEAD, and TITLE.\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\/26533","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\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26533"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26533\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26533"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}