Search code examples
jspelcontext-param

JSP: getting context-param in JSP doesnt work


I have my web.xml file where i define the context-param and then i want to get the value from the variable in my jsp-file. so i tried ${initParam.variablename} but the ouput is empty.

the xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <context-param>
        <description>The relative path to product images</description>
        <param-name>productImagePath</param-name>
        <param-value>img/products/</param-value>
    </context-param>

html

categoryImagePath: ${initParam.categoryImagePath}

Thanks in advance


Solution

  • You need to add the url pattern in your web.xml as ,

    <servlet-mapping>
    <servlet-name>abc</servlet-name>
    <url-pattern>jspPage</url-pattern>
    </servlet-mapping>
    

    And also check whether you have EL support in your jsp page. As PSR mentioned it should be jsp.