如何在EL中评估scriptlet变量? [英] How to evaluate a scriptlet variable in EL?
问题描述
我想知道是否在<c:if>
语句中使用了JSP.
I was wondering if there was anyway of using JSP in <c:if>
statement.
例如
<c:if test="${ param.variable1 == 'Add' <% JSP variable clause %>}">
所以我也想检查我的JSP变量.
So I want my JSP variable to checked against as well.
有什么建议吗?我无知地试着仅仅坚持该子句,显然那是行不通的.
Any suggestions? I have tried ignorantly just sticking in the clause, obviously it did not work.
谢谢
推荐答案
所以您想在EL中评估 scriptlet 变量?将其存储为请求属性.
So you want to evaluate a scriptlet variable in EL? Store it as a request attribute.
<%
String var = "some";
request.setAttribute("var", var);
%>
<c:if test="${param.variable1 == 'Add' && var == 'some'}">
但是,这没有任何意义.您应该避免 脚本并使用JSTL/EL准备此变量.因此,如果您使功能要求更加明确,例如如何使用JSTL/EL做到这一点(插入 scriptlet 代码片段?"),那么我们将能够提出正确的方法.
However, this makes no sense. You should avoid scriptlets altogether and use JSTL/EL to prepare this variable. So if you make the functional requirement more clear, e.g. "How do I do this (insert scriptlet code snippet) using JSTL/EL?", then we'll be able to suggest the right approach.
例如,您可以使用<c:set>
在EL作用域中设置变量.
For example, you could use <c:set>
to set a variable in EL scope.
<c:set var="var" value="some" scope="request" />
另请参见:
- 我们的EL Wiki页面
- <%= foo%>之间的差异和$ {foo}
- 直接在脚本<%XY%>中使用EL $ {XY} ;
- 什么是隐式对象?是什么意思?
- Our EL wiki page
- Difference between <%= foo %> and ${ foo }
- Use EL ${XY} directly in scriptlet <% XY %>
- What are implicit objects? What does it mean?
See also:
这篇关于如何在EL中评估scriptlet变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!