Java Expression works in JSTL tags but not in Stru

2019-03-03 19:58发布

I am using "JSTL" ans "struts2" in my project.I am trying set a value in the scope using JSTL and Struts2 tag as follows,

<div id="id1"></div>
<div id="id2"></div>
<%               
   int b=10;
 %>
<c:set var="test2" value="<%= b %>"/>
<s:set var="test3" value=" <%=b%>" />
<script>
 document.getElementById("id1").innerHTML="${test2}"; //10
 document.getElementById("id2").innerHTML="${test3}"; //nothing is displayed.
</script>

The output is 10 only. My doubt is why the expression <%= b %> works in <c:set> tag and not work in <s:set> tag?

1条回答
【Aperson】
2楼-- · 2019-03-03 20:22

Struts tags doesn't allow scriptlects in the tag's attributes. But you can try

<s:set var="test3"><%=b%></s:set>
查看更多
登录 后发表回答