Servlet Init Params Introduction

Bharath Thippireddy
A free video tutorial from Bharath Thippireddy
IT Architect and Best Selling Instructor- 350000+ students
4.5 instructor rating • 30 courses • 402,165 students

Learn more from the full course

JDBC Servlets and JSP - Java Web Development Fundamentals

Create Java Web Applications from scratch in easy steps

08:45:32 of on-demand video • Updated February 2021

  • Develop Dynamic Web Applications
  • Learn the fundamentals of JDBC and using the different interfaces in the JDBC API
  • Learn , Create and Deploy Servlets
  • Initialize parameters dynamically
  • Learn how to manage sessions
  • Understand how JSPs can help to separate Web logic and functionality from page layout
  • Learn the meaning and importance of MVC
  • Explore how to make JSPs smaller and more powerful with JSTL, custom tags
  • Understand and Implement Connections Pooling
  • Secure you web application
  • Learn how to manage sessions
English By the end of this lecture u wil learn what is init params are how to configure them. And why do we need them in the first place. init params are name value pairs off textural information that are supplied to a servlet diecratievely that is through the web.xml file during its initialization face could be the location of a folder were you want all the uploaded files to be saved to. or it could be simply the database as username and password the information itself these names and values could be anything but they can be easily passed to a servlet through the web.xml file you create in it perhaps in the web.xml inside your servlet element. Once you give it a name and declare the servlet class you can create init params using the init Param element init hyphen param element within this. You have param name and Param value here in this example. I'm using db user my database user I am passing it through. Init param to the Servlet and the user value is a root root is the user name that should be used. So once we configure this in the web.xml the servlet container will pass the params to thr servlet through the in it method during the initialization phase. The container will create. a servelt config object it reads this web dot xml file and then it uses this information and it sets the information into the servlet config Then you can easily retrieve that information inside your servlet class when you develop your servlet You can say config dot get in it. param is the method so the servelt config has a get in it. param parameter method to which you pass the name that you have used in the web.xml in which u will get the value back. You can configure any number off in it. Params inside the web.xml and u can retrive them in the servelt code in the init method the main advantage of using init params is will not have any hard coded values so you will not be hard coding your database user names and passwords. in your servelts and even if file location to which you want to save uploaded files. The data itself could be anything but using init params we can avoid hard coding of values which is a big advantage because every time the database username or password changes you need not go to your servlet code and change the code compile the code and redeploy the whole thing. a developer need not be involved at all. The deployer who ever is taking care of the deployment can simply open the web.xml file in a notepad or something and change the value and restart the server So from this lecture you have learned that init parameters are name value pairs of textual information that can be passed to a servlet to the web.xml You can configure init pramas in the web.xml right were we declare the servlet and the container creates a servlet config object and it passes the servlet config through the in it method to this servlet inside the servlet We wil use the config objects get init parameter method to retrieve the values of the init params