{"id":1482,"date":"2011-02-12T18:02:45","date_gmt":"2011-02-12T12:32:45","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1482"},"modified":"2011-02-12T18:02:45","modified_gmt":"2011-02-12T12:32:45","slug":"how-container-handles-the-servlet-request","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/how-container-handles-the-servlet-request\/","title":{"rendered":"How container handles the Servlet request"},"content":{"rendered":"<p>1. User clicks a link that has a URL of Servlet.<\/p>\n<figure id=\"attachment_1485\" aria-describedby=\"caption-attachment-1485\" style=\"width: 495px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Client-Browse-Servlet-URL.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1485 \" title=\"Client Browse Servlet URL\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Client-Browse-Servlet-URL.jpg?resize=495%2C189&#038;ssl=1\" alt=\"Client Browse Servlet URL\" width=\"495\" height=\"189\" \/><\/a><figcaption id=\"caption-attachment-1485\" class=\"wp-caption-text\">Client Browse Servlet URL<\/figcaption><\/figure>\n<p><!--more-->2. Container (Apache Tomcat is one of the example) sees that the request is for servlet , so create two objects :<br \/>\n<strong>HttpServletRequest<br \/>\nHttpServletResponse<\/strong><\/p>\n<figure id=\"attachment_1486\" aria-describedby=\"caption-attachment-1486\" style=\"width: 463px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/HttpServletRequest-and-HttpServletResponse.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1486\" title=\"HttpServletRequest and HttpServletResponse\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/HttpServletRequest-and-HttpServletResponse.jpg?resize=463%2C179&#038;ssl=1\" alt=\"HttpServletRequest and HttpServletResponse\" width=\"463\" height=\"179\" \/><\/a><figcaption id=\"caption-attachment-1486\" class=\"wp-caption-text\">HttpServletRequest and HttpServletResponse<\/figcaption><\/figure>\n<p>3. Container finds correct servlet on the basis of URL passed with the help <strong>deployment descriptor<\/strong> (web.xml) file. Creates \/ Allocate thread for that request and pass request and response object to servle thread.<\/p>\n<figure id=\"attachment_1487\" aria-describedby=\"caption-attachment-1487\" style=\"width: 437px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Create-Thread-for-Servlet.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1487\" title=\"Create Thread for Servlet\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Create-Thread-for-Servlet.jpg?resize=437%2C180&#038;ssl=1\" alt=\"Create Thread for Servlet\" width=\"437\" height=\"180\" \/><\/a><figcaption id=\"caption-attachment-1487\" class=\"wp-caption-text\">Create Thread for Servlet<\/figcaption><\/figure>\n<p>4. Container calls the servlets <strong>service()<\/strong> method, on the type of request, service calls <strong>doGet() or doPost()<\/strong> methods.<\/p>\n<figure id=\"attachment_1488\" aria-describedby=\"caption-attachment-1488\" style=\"width: 462px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Service-method-of-servlet.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1488\" title=\"Service method of servlet\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Service-method-of-servlet.jpg?resize=462%2C277&#038;ssl=1\" alt=\"Service method of servlet\" width=\"462\" height=\"277\" \/><\/a><figcaption id=\"caption-attachment-1488\" class=\"wp-caption-text\">Service method of servlet<\/figcaption><\/figure>\n<p>5. Lets assume that service calls the doPost() method. doPost() method<strong> generates dynamic page<\/strong> and add the page in response object.<\/p>\n<figure id=\"attachment_1489\" aria-describedby=\"caption-attachment-1489\" style=\"width: 469px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Servlet-doPost-response-object.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1489\" title=\"Servlet - doPost  - response object\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Servlet-doPost-response-object.jpg?resize=469%2C223&#038;ssl=1\" alt=\"Servlet - doPost  - response object\" width=\"469\" height=\"223\" \/><\/a><figcaption id=\"caption-attachment-1489\" class=\"wp-caption-text\">Servlet - doPost - response object<\/figcaption><\/figure>\n<p>6. Thread completes, container <strong>converts the response object into HttpResponse<\/strong> object and <strong>destroys the response and request object<\/strong>.<\/p>\n<figure id=\"attachment_1490\" aria-describedby=\"caption-attachment-1490\" style=\"width: 475px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/destroy-response-and-request-object.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1490 \" title=\"destroy response and request object\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/destroy-response-and-request-object.jpg?resize=475%2C169&#038;ssl=1\" alt=\"destroy response and request object\" width=\"475\" height=\"169\" \/><\/a><figcaption id=\"caption-attachment-1490\" class=\"wp-caption-text\">destroy response and request object<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>How container handles the Servlet request or How the apache Tomcat works<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[11],"tags":[125],"class_list":["post-1482","post","type-post","status-publish","format-standard","hentry","category-servlet","tag-j2ee"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1959,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/create-servlet-using-annotation\/","url_meta":{"origin":1482,"position":0},"title":"Create Servlet using Annotation &#8211; Servlet 3.0","author":"Jitendra","date":"April 13, 2011","format":false,"excerpt":"Create the Servlet without any deployment descriptor. Using Annotations","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3150,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/merge-pdf-in-salesforce-using-java-itextpdf-and-oauth-2\/","url_meta":{"origin":1482,"position":1},"title":"Merge PDF in Salesforce Using Java, ITextPDF and OAuth 2","author":"Jitendra","date":"December 9, 2012","format":false,"excerpt":"Its long time, since i wrote any article because of my busy schedule However this time i came with advance one. In this article we are going to use the J2EE (Servlet) to Merge PDF attachment inside salesforce with the help of OAuth and ITextPDF jar file. The reason of\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Create Remote Access in Salesforce.com for OAuth 2","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/12\/Create-Remote-Access-in-Salesforce.com_.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/12\/Create-Remote-Access-in-Salesforce.com_.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/12\/Create-Remote-Access-in-Salesforce.com_.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1501,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/difference-in-sendredirect-and-requestdispatcher-in-servlet\/","url_meta":{"origin":1482,"position":2},"title":"Difference in SendRedirect() and RequestDispatcher() in Servlet","author":"Jitendra","date":"February 13, 2011","format":false,"excerpt":"difference in SendRedirect() and RequestDispatcher() in Servlet","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1494,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/life-cycle-of-servlet\/","url_meta":{"origin":1482,"position":3},"title":"Life Cycle of Servlet","author":"Jitendra","date":"February 12, 2011","format":false,"excerpt":"Explain Life Cycle of Servlet","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"Servlet Life Cycle","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Servlet-Life-Cycle.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1464,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/what-is-preinitialization-of-servlet\/","url_meta":{"origin":1482,"position":4},"title":"What is preinitialization of servlet","author":"Jitendra","date":"February 8, 2011","format":false,"excerpt":"What is preinitialization of servlet","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1467,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/difference-between-servletcontext-and-servletconfig\/","url_meta":{"origin":1482,"position":5},"title":"Difference between servletContext and ServletConfig","author":"Jitendra","date":"February 8, 2011","format":false,"excerpt":"What is difference between servletContext and ServletConfig?","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1482"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1482\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}