How To Declare Initialization Parameters For JSP Page In web.xml file
Servlet initialization parameters are declared inside web.xml page and are used to pass the value to the servlet as a part of configuration.Now the question comes that since we do not make an entry for JSP inside web.xml page,how to pass the init parameters to the JSP page.We should remember that a JSP page is a servlet at the end of the day.A JSP is ultimately converted into a servlet then only it processes requests.Like the entry for init parameters in web.xml in case of servlet we make an entry for the JSP page as well,but with a slight difference.The web.xml file looks like this :
<servlet> <servlet-name>myJSP</servlet-name> <jsp-file>/MyJsp.jsp</jsp-file> <init-param> <param-name>paramName</param-name> <param-value>paramValue</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>myJSP</servlet-name> <url-pattern>/MyJsp.jsp</url-pattern> </servlet-mapping>
Here we can find that the same way as we declare init paramters for servlet within the servlet tags,the same way we make an entry for the JSP page so that the init parameters can be declared for that particular JSP page.The only difference is that instead of he <servlet-class> tag we use <jsp-file> tag.The url pattern for the JSP page is same as the JSP file name as we use the JSP file name as URL pattern in the request.Inside the <jsp-file> tag we use the JSP file name with .jsp extension because we need to access the JSP page and not the servlet class.
This is the way we declare servlet init parameters for the JSP page inside the web.xml file.We call it as servlet init parameters for JSP page because these init parameters are sent to the servlet which is the result of translation of the JSP page.And these are used as the configuration parameters for the translated servlet.Now the init parameters can be accessed in he JSP page code.
Number of View :6923Related posts:
- Servlet Init Params How to get init parametrs in servlets Retreiving init params in servlets
- Difference Between Parameters And Attributes In Servlets/JSP Parameter vs. Attribute
- Tomcat Welcome file list Tomcat directory listing setup welcome files in tomcat
- Life Cycle Of A Servlet Explained Handling Servlet Life-Cycle Events Servlet Life Cycle Servlet Interview Questions Java Servlet Programming
- How To Get The Parameters From One Servlet To Another Using Request
Tags: apache tomcat, init parameters, j2ee, java, jsp, servlet, web application, web.xml
This entry was posted on Sunday, May 20th, 2012 at 8:15 am and is filed under Java, OPPS, software, Tech-Tips, Tips & Tricks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.