Master java skills

config Implicit Object

config object is of type ServletConfig. This can be used to get initialization parameter for a JSP page. The config object is created by the web container for each jsp page.

example

index.html

<html>
<form action="welcome">
	Username : <input type="text" name="username"> <br>
	<input type="submit" value="Submit">
</form>
</html>

web.xml file

<web-app>  
  
  <servlet>  
    <servlet-name>exampleServlet</servlet-name>  
    <jsp-file>/welcome.jsp</jsp-file>  
  
    <init-param>  
      <param-name>pName</param-name>  
      <param-value>pValue</param-value>  
    </init-param>  
  
  </servlet>  
  
  <servlet-mapping>  
    <servlet-name>exampleServlet</servlet-name>  
    <url-pattern>/welcome</url-pattern>  
  </servlet-mapping>  
  
</web-app> 

welcome.jsp

<html>
  <body>
    <%   
      out.print("Welcome " + request.getParameter("username"));  
      String paramName = config.getInitParameter("pName");  
      out.print("<br>Initial parameter value is = " + paramName);  
    %>  
  </body>
</html>

Test the application