如何在JSP中将服务器端变量传递到核心标记中? [英] How can I pass a server side variable into a core tag in JSP?

查看:56
本文介绍了如何在JSP中将服务器端变量传递到核心标记中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此表达标签对我来说是正确的值 <%= 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}">&nbsp;<bean:message key="WriteScript.msgNonAuthoritative"></bean:message></c:if>

方法是

public Boolean NonAuthoritative() {
    return nonAuthoritative;
}

推荐答案

有2个问题:

  1. 小脚本和EL不在同一范围内. ${drug}中的drug必须与页面,请求,会话或应用程序范围中现有属性的名称匹配.如果要在 scriptlet 中而不是在控制器中准备drug,那么您应该自己将其作为属性放在这些作用域之一中.

  1. 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 preparing drug 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 依赖


  • (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中将服务器端变量传递到核心标记中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆