问题描述
此表达标签对我来说是正确的值 <%= drug.NonAuthoritative%>
This expression tag outpus a correct value for me <%=drug.NonAuthoritative%>
我无法恢复药物的价值.非授权用于C标签
while I cant recover the value of drug.NonAuthoritative for use in a C tag
<c:if test="${drug.NonAuthoritative}"> <bean:message key="WriteScript.msgNonAuthoritative"></bean:message></c:if>
方法是
public Boolean NonAuthoritative() {
return nonAuthoritative;
}
推荐答案
有2个问题:
-
小脚本和EL不在同一范围内.
${drug}
中的drug
必须与页面,请求,会话或应用程序范围中现有属性的名称匹配.如果要在 scriptlet 中而不是在控制器中准备drug
,那么您应该自己将其作为属性放在这些作用域之一中.
Scriptlets and EL do not share the same scope. The
drug
in${drug}
has to match the name of an existing attribute in the page, request, session or application scope. If you're preparingdrug
in a scriptlet instead of in a controller, then you should put it as an attribute in one of those scopes yourself.
<%
Drug drug = new Drug();
// ...
request.setAttribute("drug", drug);
%>
(Nathan部分回答), EL 依赖 Javabeans规范.对于非布尔型属性,${drug.propertyName}
需要公共方法getPropertyName()
;对于布尔型属性,isPropertyName()
需要公共方法.所以,这应该做
(as partly answered by Nathan), EL relies on Javabeans specification. The ${drug.propertyName}
requires a public method getPropertyName()
for non-boolean properties or isPropertyName()
for boolean properties. So, this should do
public class Drug {
private boolean nonAuthorative;
public boolean isNonAuthorative() {
return nonAuthorative;
}
// ...
}
使用
<c:if test="${drug.nonAuthoritative}">
(请注意外壳!)
这篇关于如何在JSP中将服务器端变量传递到核心标记中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!