How to get JSP scriptlet value in struts tag

六眼飞鱼酱① 提交于 2019-12-04 03:38:59

问题


Here is my code:

<% request.setAttribute("lcItem", "Hello"); %>

If I do as following, I'm not getting the value:

<s:property value="%{lcItem}" />
<s:property value="lcItem" />

Any suggestions?


回答1:


This works perfectly..

<%       
   request.setAttribute("lcItem", LeftContentItem);
%>

<s:property value="#request['lcItem']" />

Note: According to the Scope we use we should specify the #request .. etc




回答2:


You can write your code 2 ways

  1. <% request.setAttribute("lcItem", "Hello"); %>
  2. <% pageContext.setAttribute("lcItem", "Hello"); %>

then if you want to access these values in Struts2 Components you might use #attr. as prefix.

Example

<s:property value="#attr.lcItem">

Note: It will work fine with request and "pageContext".

<s:property value="lcItem" /> will not work because "lcItem" is not available in the Value Stack.


来源:https://stackoverflow.com/questions/724887/how-to-get-jsp-scriptlet-value-in-struts-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!