JSP Config – Implicit Objects
JSP Config is an implicit object which is used to transmit the configuration details to the JSP page. In JSP, Config is an instance of type ServletConfig. This implicit object is used to acquire an initialization parameter for a certain JSP page. For each JSP page, the config object is generated through the web container. JSP’s config object carries the configuration pieces of information like the username, password, driver name, servlet name, servlet context, specification names, and their values settle in the web.xml (configuration file).
It is an object of type javax. servlet.ServletConfig interface.
Through web.xml file the detail is send to JSP file. To fetch this detail the Config object is used. Normally, it is used extensively for the initialization parameters like as the paths or file locations from the web.xml file.
Note: JSP Config object has scope only up to a single JSP page.
Methods of ServletConfig interface are listed alongside the action performed from the below table as follows:
|ServletContext getServletContext()||From the session, this method withdraws an object with a name.|
|String getInitParameter(String name)||This method receives an object saved in session with a name, or null.|
|Enumeration getInitParameterNames()||In a session, this method places an object with a name.|
|String getServletName()||This method gives back a RequestDispatcher that behaves as a cover for the resource at the path.|
We will be proposing examples directly and later on will append the visual aid representing JSP pages as an output. So example of JSP Config implicit object is as follows:
- In this example, the various variables and their values are contained in the ‘web.xml file‘.
- The config object is in ‘index.jsp‘ file retrieves that information and displays it to the user.
Example 1: index.html File
Example 2: web.xml File
Example 3: ‘welcome.jsp’ FIle
These are the screenshots of the outputs of the above JSP page.
Please Login to comment...