简体   繁体   English

将值设置为struts1中的变量

[英]Set value into variable in struts1

I can iterate the list in struts1 using below code : 我可以使用以下代码迭代struts1中的列表:

<logic:iterate name="listMsg" id="listMsgId">
<p>
    List Messages <bean:write name="listMsgId"/>
</p>
</logic:iterate>

But how can I set variable within this tag. 但是,如何在此标记内设置变量。

For example I want to fetch data from the above tag and initialize in some variable. 例如,我想从上面的标签中获取数据并在某个变量中进行初始化。

<logic:iterate name="listMsg" id="listMsgId">
<p>
    <%
        String firstName = "Get data from this list";
     %>
    List Messages <bean:write name="listMsgId"/>
</p>
</logic:iterate>

How can I achieve the above one using struts1 and java. 如何使用struts1和java实现以上功能。

Is it possible? 可能吗? If yes then how? 如果是,那怎么办?

one solution, and imo the better one, is to use jsp jstl. 一种解决方案,而imo更好的解决方案是使用jsp jstl。 See the example below: 请参阅以下示例:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--@elvariable id="messages" type="java.util.List"--%>

<c:forEach items="${messages.msgList}" var="message" varStatus="st">
    <c:set var="varName" value="varValue"/>
    <p>${message.id}</p>
    <p>${varName}</p> <!-- to print -->
</c:forEach>

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM