JSP表达式在JSTL标记中有效,但在Struts 2标记中无效 [英] JSP Expression works in JSTL tags but not in Struts 2 tags
本文介绍了JSP表达式在JSTL标记中有效,但在Struts 2标记中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在项目中使用JSTL和Struts 2.我正在尝试使用JSTL和Struts 2标记在范围内设置一个值,如下所示:
I am using JSTL and Struts 2 in my project. I am trying to set a value in the scope using JSTL and Struts 2 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>
输出仅为 10
.我的疑问是为什么表达式<%= b%>
在< c:set>
标记中起作用而在< s:set>中不起作用;
标签?
The output is 10
only. My doubt is why the expression <%= b %>
works in <c:set>
tag and does not work in <s:set>
tag?
推荐答案
Struts标记不允许在标记的属性中使用脚本.但是你可以尝试
Struts tags doesn't allow scriptlects in the tag's attributes. But you can try
<s:set var="test3"><%=b%></s:set>
这篇关于JSP表达式在JSTL标记中有效,但在Struts 2标记中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文