JSP Tutorials

JSP Config
Previous Home Next
adplus-dvertising

JSP config

It is an implicit object of type ServletConfig and it can be get initialization JSP page with config object is created by the web container.

JSP config is getting a initialization parameter from the web.xml file by web container.

Example of JSP config

index.html
    <form action="welcome">  
    <input type="text" name="uname">  
    <input type="submit" value="go"><br/>  
    </form>  

    <form action="welcome">  
    <input type="text" name="uname">  
    <input type="submit" value="go"><br/>  
    </form>  
web.xml
    <web-app>  
          <servlet>  
    <servlet-name>sonoojaiswal</servlet-name>  
    <jsp-file>/welcome.jsp</jsp-file>  
          <init-param>  
    <param-name>dname</param-name>  
    <param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>  
    </init-param>  
          </servlet>  
          <servlet-mapping>  
    <servlet-name>sonoojaiswal</servlet-name>  
    <url-pattern>/welcome</url-pattern>  
    </servlet-mapping>  
          </web-app>  
    <web-app>  
          <servlet>  
    <servlet-name>sonoojaiswal</servlet-name>  
    <jsp-file>/welcome.jsp</jsp-file>  
          <init-param>  
    <param-name>dname</param-name>  
    <param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>  
    </init-param>  
          </servlet>  
          <servlet-mapping>  
    <servlet-name>sonoojaiswal</servlet-name>  
    <url-pattern>/welcome</url-pattern>  
    </servlet-mapping>  
          </web-app>  
welcome.jsp
    <%   
    out.print("Welcome "+request.getParameter("uname"));  
      
    String driver=config.getInitParameter("dname");  
    out.print("driver name is="+driver);  
    %>  

    <%   
    out.print("Welcome "+request.getParameter("uname"));  
      
    String driver=config.getInitParameter("dname");  
    out.print("driver name is="+driver);  
    %>  

Output :

Previous Home Next