HTML 和 JSP 脚本中的串联挑战与支柱

concatenation challenge in html and jsp scriptlets with struts

本文关键字:挑战 JSP 脚本 HTML      更新时间:2023-09-26
<script>
   var myValue = ${valueBean};
</script>

myValue 的值为 5

<input type="text" name="<%=curName%>'[' + myValue +'].otherList[' + myValue + '].'<%=curProp%>" value="<%=(String) currentItr.next()%>"/>

当我查看源代码时,生成的 html 不断给我

<input type="text" name="myList'[' + myValue +'].otherList[' + myValue + '].'someProp" value="XXX"/>

什么时候应该

<input type="text" name="myList[5].otherList[5].someProp" value="XXX"/>

是否在做不同的事情,我不太清楚我的连接问题在哪里。 请帮忙!

试试这个:

<input type="text" name="<%=curName%>[${valueBean}].otherList[${valueBean}].<%=curProp%>" value="<%=(String) currentItr.next()%>"/>
使用

myValue 的 istead 你可以使用 jstl 并使用 jstl c:out 标签直接嵌入 valueBean

name="myList'[' + myValue +'].otherList[' + <c:out value='${valueBean}'/> + '].'someProp"