开发者

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

开发者 https://www.devze.com 2022-12-14 23:48 出处:网络
When I inc开发者_Python百科lude a JSP, either by <jsp:include /> and specify parameters - they are perfectly accessible by EL ${param.XXX} but not by OGNL %{#parameters.XXX}.

When I inc开发者_Python百科lude a JSP, either by <jsp:include /> and specify parameters - they are perfectly accessible by EL ${param.XXX} but not by OGNL %{#parameters.XXX}.

For example:

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

and in fragment.jsp

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

WHY ??? What should I use instead in Struts Tags ?

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


This is what I do to solve the problem:

In including page:

<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 it works for you!


I encountered this problem recently. I found the reason is that the parameters in <s:include> is not stored in the request.parameters object of ActionContext, but stored in HttpServletRequest of JSP page. So the parameters can be obtained through EL(${param.xxx}) or <% request.getParameters("xxxx") %>, but we can't get it through (struts) ongl. Because the parameters are not in the ActionContext.

If you insist on using the ongl, you can add the parameters into ActionContext through jsp <% %> or EL and then you can obtain the parameters through ongl.


http://prodia.co.uk/blog/doahh/entry/struts2_s_include_and_passing


Try the following.

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

精彩评论

暂无评论...
验证码 换一张
取 消