SevletConfigExample Program In Java

In this tutorial we learn how to use ServletConfig interface in Servlet based applications  and  how to run that servlet in Tomcat which is integrated with eclipse.

How to retrieve servlet config information in Servlet class?

In below Servlet class first we need to create ServletConfig reference by calling the getServletConfig() and then we need to retrieve the config information of this servlet which is configured in webxml.


1. Create a dynamic project in eclipse.

        Create a dynamic web project in eclipse(click “new” ->Dynamic web project) and add below servlet class to project, If you dont know how to create dynamic web project please see my previouse example Helloworld Servlet Example Program with video tutorial.

2. Write the Servlet class,


 3. configure the servlet in deployment descriptor i.e in web.xml


 4. deploy and run the servlet in server.

Right click on the project and click on “Run As” -> “Run on Server”.





Download  Source Code


Posted in servlets and tagged .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.