Struts2 Struts 2中scriplet单选按钮的列表属性值

Struts2 Struts 2中scriplet单选按钮的列表属性值,struts2,radio-button,jstl,struts,ognl,Struts2,Radio Button,Jstl,Struts,Ognl,我想从循环中读取list的键和值。 下面是我尝试过的代码片段,但它不起作用 <c:forEach items="${mylist}" var="title"> <c:set var="id" value="${title.key.id}"/> <%Integer idInt = (Integer)pageContext.getAttribute("id"); String idStr = ""; if(idInt != n

我想从循环中读取
list
的键和值。 下面是我尝试过的代码片段,但它不起作用

<c:forEach items="${mylist}" var="title">
    <c:set var="id" value="${title.key.id}"/>
      <%Integer idInt = (Integer)pageContext.getAttribute("id");
      String idStr = "";
      if(idInt != null && idInt.intValue() > 0){
      idStr = idInt.toString();
      }%>
<s:radio theme="simple" name="selectedOption" list="#{idStr:title.value}"/>
</c:forEach>

0){
idStr=idInt.toString();
}%>
试试看



变量
title
位于页面范围内,但不需要scriptlet来访问它

为什么是sriplets?为什么要使用forEach?你想做什么?@AleksandrM:我想从循环中读取列表的键和值。列表的键?你是指索引吗?@AleksandrM yes index(listkey)和value在这种情况下,这是什么
title.key.id
<c:forEach items="${mylist}" var="title">
  <s:radio theme="simple" name="selectedOption" list="#{#attr.title.key.id:#attr.title.value}"/>
</c:forEach>