{"id":1467,"date":"2011-02-08T23:32:27","date_gmt":"2011-02-08T18:02:27","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1467"},"modified":"2011-02-08T23:32:27","modified_gmt":"2011-02-08T18:02:27","slug":"difference-between-servletcontext-and-servletconfig","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/difference-between-servletcontext-and-servletconfig\/","title":{"rendered":"Difference between servletContext and ServletConfig"},"content":{"rendered":"<p><strong>ServletConfig<\/strong><br \/>\nServletConfig is implemented by the servlet container to initialize a single servlet <strong>using init()<\/strong>. \u00a0you can pass initialization parameters to the servlet using the <strong>web.xml<\/strong> deployment descriptor. <strong>Every servlet has its own ServletConfig object.<\/strong><\/p>\n<p><!--more-->Example code:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;servlet&gt;\n&lt;servlet-name&gt;ServletConfigTest&lt;\/servlet-name&gt;\n&lt;servlet-class&gt;com.shivasoft.ServletConfigTest&lt;\/servlet-class&gt;\n&lt;init-param&gt;\n&lt;param-name&gt;article&lt;\/param-name&gt;\n&lt;param-value&gt;Difference between servletContext and ServletConfig&lt;\/param-value&gt;\n&lt;\/init-param&gt;\n&lt;\/servlet&gt;\n<\/pre>\n<p><strong>ServletContext<\/strong><br \/>\nServletContext is implemented by the servlet container for all servlet to communicate with its servlet container. It is applicable only within a single Java Virtual Machine.<br \/>\nThe ServletContext object is contained <strong>within the ServletConfig object<\/strong>. That is, the ServletContext can be accessed using the ServletConfig object within a servlet. You can specify param-value pairs for ServletContext object in \u00a0<strong>&lt;context-param&gt;<\/strong> tags in web.xml file. <strong>ServletContext is created at the application level and shared by all the Servlet codes.<\/strong><\/p>\n<p>Example : Database string used by the application.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;context-param&gt;\n&lt;param-name&gt;dbString&lt;\/param-name&gt;\n&lt;param-value&gt;Provider=MySQLProv;Data Source=shivasoft;User Id=shiva; Password=soft;&lt;\/param-value&gt;\n&lt;\/context-param&gt;\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is difference between servletContext and ServletConfig?<\/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_post_was_ever_published":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":""},"categories":[11],"tags":[125],"class_list":["post-1467","post","type-post","status-publish","format-standard","hentry","category-servlet","tag-j2ee"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1477,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/why-not-to-write-constructor-in-servlet\/","url_meta":{"origin":1467,"position":0},"title":"Why not to write constructor in Servlet","author":"Jitendra","date":"February 11, 2011","format":false,"excerpt":"Why not to write constructor 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":1479,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/example-to-override-the-init-method-of-the-servlet\/","url_meta":{"origin":1467,"position":1},"title":"Example to Override the init() method of the servlet","author":"Jitendra","date":"February 11, 2011","format":false,"excerpt":"Example to Override the init() method of the 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":1439,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/difference-in-httpservlet-and-genericservlet\/","url_meta":{"origin":1467,"position":2},"title":"Difference in HttpServlet and GenericServlet","author":"Jitendra","date":"February 4, 2011","format":false,"excerpt":"What is the basic Difference in HttpServlet and GenericServlet","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1664,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/step-by-step-dwr-application-simple-ajax-in-java\/","url_meta":{"origin":1467,"position":3},"title":"Step by Step DWR Application &#8211; Simple AJAX in JAVA","author":"Jitendra","date":"March 15, 2011","format":false,"excerpt":"Step by Step DWR Application - Simple AJAX in JAVA","rel":"","context":"In &quot;JSP&quot;","block_context":{"text":"JSP","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/jsp\/"},"img":{"alt_text":"How DWR works in Java","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/How-DWR-works-in-Java.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1494,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/life-cycle-of-servlet\/","url_meta":{"origin":1467,"position":4},"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":1467,"position":5},"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":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1467","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=1467"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1467\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}