Jsp 如何将c:forEach标记的循环索引附加到Struts HTML标记属性?

Jsp 如何将c:forEach标记的循环索引附加到Struts HTML标记属性?,jsp,struts,jstl,struts-html,Jsp,Struts,Jstl,Struts Html,如何将c:forEach标记的循环索引附加到struts select/text标记的属性 比如说 <%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%> <c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC"> <div class="section guest-details"> <ht

如何将c:forEach标记的循环索引附加到struts select/text标记的属性

比如说

<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>

<c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC">
    <div class="section guest-details">
       <html:select property='title_guest<c:out value="${gC.index}"/>'>
          <html:options collection="titles" property="code" labelProperty="value" />
       </html:select>
    </div>
 </c:forEach>
正确输出所需的HTML

我做错了什么,我应该使用EL来创建填充html:select标记的“property”属性的字符串吗

更新

下面的代码片段也尝试过了,但也不起作用

而且,这也不起作用

<c:set var="guestTitle">title_guest${gC.index}</c:set>
<html:select property="${guestTitle}" styleClass="{required: true}">
 <html:options collection="titles" property="code" labelProperty="value" />
</html:select>
title_guest${gC.index}

这将是一个嵌套表达式,这是不允许的,请尝试使用它

<html:select property='title_guest${gC.index}'>

经过痛苦的挖掘,我似乎找到了问题所在,也找到了解决方案。c:forEach标记不会将varStatus作为脚本变量导出,因此varStatus变量不能在RT Expr中用于html:select标记的属性

但是,c:forEach确实将varStatus变量导出为pageContext属性,可以检索并用于提取索引/计数。唯一的问题是您必须导入javax.servlet.jsp.jstl.core.LoopTagStatus类,并使用该类手动重新创建varStatus变量,以便在scriplet中使用它

下面是一段有效的代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    import="javax.servlet.jsp.jstl.core.LoopTagStatus"
%>
 ...
<c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC">
  <% LoopTagStatus gN = (LoopTagStatus)pageContext.getAttribute("gC"); %>
  <html:select property='<%="title_guest"+gN.getIndex()%>'>
     <html:options collection="titles" property="code" labelProperty="value" />
  </html:select>
</c:forEach>

...
我认为这不是一个干净的解决方案(但可能是唯一的解决方案)。因此,在我接受这个答案作为最终答案之前,我会先让社区对这个答案进行投票(或者写一个更好的答案)。

            <c:forEach begin="1" end="${page.totalPages}" varStatus="lp">
                <li><a href="<c:url value="/course?page=${pageScope.lp.index}"/>">${pageScope.lp.index}</a></li>
            </c:forEach>


  • 在等待了整整两天之后……我没有收到这个问题的任何其他答案,我接受了我自己的答案
                <c:forEach begin="1" end="${page.totalPages}" varStatus="lp">
                    <li><a href="<c:url value="/course?page=${pageScope.lp.index}"/>">${pageScope.lp.index}</a></li>
                </c:forEach>