<div dir="ltr" style="text-align: justify;" trbidi="on">Difference between ServletConfig and ServletContext in Java Servlet is popular question in java interview. Let see following are differences.</p>
<p><i><b>No. of web applications = That many number of ServletContext objects</b></i><br />
<i><b><br />
</b></i> <i><b>No. of servlet classes = That many number of ServletConfig objects.</b></i></p>
<p><b>Usage of <i>ServletContext</i> Interface</b></p>
<p>There can be a lot of usage of ServletContext object. Some of them are as follows:</p>
<div align="center" id="ads-id"></div>
<ul style="text-align: left;">
<li>The object of ServletContext provides an interface between the container and servlet.</li>
<li>The ServletContext object can be used to get configuration information from the web.xml file.</li>
<li>The ServletContext object can be used to set, get or remove attribute from the web.xml file.</li>
<li>The ServletContext object can be used to provide inter-application communication.</li>
<li>ServletContext object will be available even before giving the first request</li>
<li>In web.xml – <b><i><;context-param>;</i></b> tag will be appear under<i><b> <;web-app>;</b></i> tag</li>
</ul>
<p></p>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;"><b>Popular Tutorials</b></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/2012/06/spring-30-baby-step-to-learn.html"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/2012/12/spring-web-mvc-framework-chapter-38.html"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/2016/06/introduction-to-spring-boot-a-spring-boot-complete-guide.html"><em><strong>Spring Boot Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/2013/02/spring-security-take-baby-step-to-secure.html"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/2012/07/introduction-to-aop-in-spring.html"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/2012/12/using-spring-jdbc-framework-chapter-32.html"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/2017/01/spring-hateoas-hypermedia-driven-restful-web-service.html"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/2017/01/microservices-with-spring-boot.html"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/2013/06/jax-rs-web-service-tutorial.html"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/2013/01/core-java-baby-step-to-be-best-java-ian.html"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/2012/03/hibernate-3-on-baby-steps.html"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/2012/12/spring-batch-process-with-example.html"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<p>
<b>Usage of <i>ServletConfig</i> Interface</b></p>
<ul style="text-align: left;">
<li>ServletConfig is implemented by the servlet container to initialize a single servlet using init(). That is, you can pass initialization parameters to the servlet using the web.xml deployment descriptor. For understanding, this is similar to a constructor in a java class.</li>
<li>An object of ServletConfig is created by the web container for each servlet. This object can be used to get configuration information from web.xml file.</li>
<li>If the configuration information is modified from the web.xml file, we don&#8217;t need to change the servlet. So it is easier to manage the web application if any specific content is modified from time to time.</li>
<li>We should give request explicitly, in order to create ServletConfig object for the first time</li>
<li>In web.xml – <b><i><;init-param>;</i></b> tag will be appear under <i><b><;servlet-class>; </b></i>tag</li>
</ul>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;"><b>Servlet Related Posts</b></p>
<ol style="text-align: left;">
<li><b><a href="https://dineshonjava.com/2013/12/java-servlets-overview.html">Java Servlets Overview</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/servlet-life-cycle.html">Servlet Life Cycle</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/hello-world-example-in-servlet-interface.html">Servlet Example</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/difference-between-genericservlet-and.html"> Difference between GenericServlet and HttpServlet<br />
</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/what-is-web-application-servlet.html">What is web application?</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/advantages-of-servlets-over-cgi.html">Advantages of Servlets over CGI</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/difference-between-genericservlet-and.html">GenericServlet Example</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/requestdispatcher-interface.html">RequestDispatcher Example</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/servletconfig-interface.html">ServletConfig</a></b></li>
<li><b><a href="https://dineshonjava.com/2013/12/servletcontext-interface.html">ServletContext </a></b></li>
<li><b><a href="https://dineshonjava.com/2014/01/servlet-filters.html">Servlet Filter Example</a></b></li>
<li><b><a href="https://dineshonjava.com/2014/01/servlets-database-access.html">Database Access Example using Sevlet</a></b></li>
<li><b><a href="https://dineshonjava.com/2014/01/servlet-upload-file-example.html">File Uploading Example using Servlet</a></b></li>
</ol>
</div>
<p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/javalangclassnotfoundexception/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '89'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…