How to config a JSP file in web.xml?

Declare the following tags in web.xml against your jsp



You need a servlet mapping, When you're dealing with a JSP as a Servlet.In order to be able to access servlet init params, you will need to create a mapping and call the JSP with the url-pattern in the mapping. JSP provides the "config" implicit object variable that eliminates the need to call getServletConfig(). You can get the init parameters from the implicit "config" object by calling getInitParameter() method or getInitParameters() method. For example,

<%= config.getInitParameter("hello");%>

If you make the url-pattern match the name of the JSP, people won't be able to skirt the web.xml configurations by typing the url of the JSP in the browser's address window.

If you want to add init-params to a JSP via web.xml, you need to create a servlet mapping for your JSP and use the url defined in that mapping when making the request.

Context init params, on the other hand are bound to the Context object (which is available to all components of the app) will be available, regardless of how your JSP was invoked.

Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |