JavaServer Pages (JSP) provides implicit objects to simplify web development. The config implicit object is used to access configuration details of a JSP page. It helps retrieve initialization parameters defined in the web.xml file.
- The config object is an instance of ServletConfig.
- It is used to fetch init parameters from web.xml.
- Its scope is limited to a single JSP page.
Methods of ServletConfig
Methods of ServletConfig interface are listed alongside the action performed from the below table as follows:
- getServletContext(): Returns the ServletContext object
- getInitParameter(String name): Returns the value of a specific initialization parameter
- getInitParameterNames(): Returns all parameter names
- getServletName(): Returns the name of the servlet/JSP page
Step-by-Step Implementation
Step 1: Create index.html
- Create a simple form to take user input
- Use action="welcome" to map request to JSP
index.html File
Step 2: Configure web.xml
- Define servlet name and JSP file mapping
- Add <init-param> to store configuration values
- Map URL pattern to access JSP
web.xml File
Step 3: Create welcome.jsp
- Access user input using request.getParameter()
- Use config.getInitParameter() to fetch value
- Display output using out object.
welcome.jsp FIle