Config Implicit Object introduction-: config is an object of type javax.servlet.ServletConfig. This object is created by Container on every JSP page. This is used to derive the initialization parameter from web.xml. The config object is used to get this configuration information from JSP Page, servlet name, configuration parameters and servlet context.
Methods of Config Implicit Object in jsp-: There are 4 method available
- String getInitParameter(String paramname)
- Enumeration getInitParameterNames()
- ServletContext getServletContext()
- String getServletName()
getInitParameter () -:This method is used to obtain its value through the name of the initialization parameter given on web.xml. For example
<%@page import="java.util.*" %> <% out.print("Parameter Value : " + config.getInitParameter("myweb")); %>
getInitParameterNames ()-: This method returns the names of the initialization parameter given in web.xml in enumeration. For example in web.xml.
<%@page import="java.util.*" %> <% Enumeration e=config.getInitParameterNames(); while(e.hasMoreElements()){ Object obj=e.nextElement(); String param=(String)obj; out.println("Intialization Parameter Name : "+ param + ""); } %>
getServletName () This method returns the servlet name from web.xml. for example
<% out.print("Servlet Name : " + config.getServletName()); %>
getServletContext() – This method returns a reference to the Servlet context.
Web.XML file-:
<web app>
<servlet>
<servlet-name>MyServelet</servlet-name>
<jsp-file>/index.jsp</jsp-file>
<init-param>
<param-name>MyWeb</param-name>
<param-value>http://www.netnic.org</param value>
</init-param>
<init-param>
<param-name>Title</param-name>
<param-value>Learning programming language</param value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>My servlet</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Here are the description given.
The web-app tag is used to configure the web application. This is the parent tags of all the tags in web.xml given above.Its open this <web-app> and close </web-app>.All the coding are written between these tags
servlet tags-:This is the parent tag of servlet-name, jsp-file and init-param.These tag start as like <servlet> and close </servlet>.
Servlet-name tags- The name of the servlet is given on this tag.
jsp-file-tag-:The name of the file to be configured is given on this tag
init-parag-:This is the parent tag of param-name and param-value. These are read from the web.xml by the servlet. Initialization parameters are given inside this tag.
param name-:Here the initialization parameter is named.
param value-:Here the value for the initialization parameter is given.
servlet-mapping-: This is the parent tag of the servlet-name and url-pattern. It maps the url patterns.
servlet-name-: Here the name of the servlet to map is given here.
url-pattern -: The url pattern is given here. Here alias file name is given for the given file on jsp-file. For example If here hello.php or hello.html or hello.txt or hello.asp is given, then the file given on jsp-file is accessed through all these files.
welcome-file-list -:This welcome-file is the parent tag of this tag.
welcome-file-:Welcome file is given here.