【问题标题】:Passing expressions to custom tags in JSP将表达式传递给 JSP 中的自定义标签
【发布时间】:2012-06-10 14:31:30
【问题描述】:

您好,我刚刚创建了在我的 JSP 中使用的自定义标签 标签的 .tld 是这样的

<?xml version="1.0" encoding="UTF-8"?>
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>acma</shortname>
<info>AccountManag</info>
<tag>
    <name>clookup</name>
    <tagclass>taglib.acm</tagclass>
    <info>Customer Lookup</info>
    <attribute>
      <name>cust_id</name>
      <required>true</required>
    </attribute>
</tag>
</taglib>

现在,当我将标签与这样的 int 值一起使用时,它的效果很好 cust_id="1"

  <dd:clookup cust_id="1"></dd:clookup>

但是当我使用 EL 时它不起作用

 <dd:clookup cust_id="${sessionScope.cust.id}"></dd:clookup>

所有教程都以 int 或其他数据类型开头,所以我无法在这里找到任何可能有帮助的资源......有什么建议吗?

【问题讨论】:

    标签: jstl jsp-tags custom-tag


    【解决方案1】:

    在您的 tld 中指定 rtexprvalue:

    <attribute>
      <name>cust_id</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
    

    更多详情请见Tag Library Descriptors。

    【讨论】:

    • 谢谢,兄弟!它有帮助!
    【解决方案2】:

    您的 EL 需要用引号括起来。

    【讨论】:

    • 我就是这样尝试的。感谢您指出。还是不行
    • 说不支持运行时表达式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多