Struts2: How to read parameters from <jsp: include>

When I enable JSP, or <jsp:include /> , and specify the parameters - they are perfectly accessible EL ${param.XXX} , but not OGNL %{#parameters.XXX} .

For instance:

 <jsp:include page="fragment.jsp"> <jsp:param value="foo" name="bar" /> </jsp:include> 

and in the .jsp snippet

 value of foo in EL : ${param.bar} value of foo in OGNL : <s:property value="%{#parameters.bar}" /> 

WHY??? What should be used instead in Struts tags?

Note: with <s:include/> instead of <jsp:include/> parameter is not available even with EL.

+4
source share
4 answers

This is what I am doing to solve the problem:

Page inclusion:

 <s:set name="searchName" value="my search term" /> <jsp:include page="/WEB-INF/page/whatever.jsp" /> 

In / WEB-INF / page / whatever.jsp:

 Your searchTerm is <s:property value="#searchName" /> 

I hope this works for you!

+3
source

I recently ran into this problem. I found that the parameters in <s:include> not stored in the request.parameters ActionContext object, but are stored in the HttpServletRequest JSP page. Thus, parameters can be obtained using EL(${param.xxx}) or <% request.getParameters("xxxx") %> , but we will not be able to execute (struts) ongl. Because the parameters are not in the ActionContext .

If you insist on using ongl, you can add parameters to the ActionContext via jsp <% %> ActionContext <% %> or EL, and then you can get the parameters via ongl.

+2
source

Try the following.

 <s:property value="%{#parameters['paramName']}"></s:property> 
-2
source

All Articles