Search code examples
javajspstruts2elognl

Using OGNL to get parameters


In one JSP page, I am including another JSP page and passing a parameter:

<jsp:include page="/WEB-INF/somepage.jsp" flush="true">
    <jsp:param name="location" value="menu"/>
</jsp:include>

In the included page, I can access the parameter using EL. This works:

${param.location}

But I cannot use the OGNL equivalent to get the same parameter. None of these work:

#parameters.location
#parameters['location']
%{#parameters.location}
%{#parameters['location']}

I know there is a work-around using <s:set var="location">${param.location}</s:set> or <c:set var="location">${param.location}</c:set> and then using OGNL: #location but I want to avoid that. I don't want to use scriptlets either.


Solution

  • Struts2 equivalent to the include tag is <s:include> that's what you should replace in your code, then apply <s:param> to parametrize it.

    <s:include value="/WEB-INF/somepage.jsp">
        <s:param name="location" value="menu"/>
    </s:include>
    

    after that you can use OGNL.