【问题标题】:How return a value from a custom tag如何从自定义标签返回值
【发布时间】:2014-08-19 22:29:14
【问题描述】:

如果我在我的函数doTag(或doStartTag)中计算一个值,我如何将它存储在一个变量中以便在我的视图中使用,在标签内,就像来自标签c:forEach 的参数varStatus在下面的例子中?

<c:forEach var="item" items="${list}" varStatus="status">
    ${status.index} - ${item}
</c:forEach>

【问题讨论】:

    标签: java jsp jstl jsp-tags taglib


    【解决方案1】:

    您可以通过这种方式在 doTag 中存储变量:

     public void doTag() throws JspException, IOException {  
            String status = "status test";
            getJspContext().setAttribute("status", status);  
            ...
        }  
    

    然后就可以正常调用了:

    ${status}
    

    类似的东西。

    【讨论】:

      猜你喜欢
      • 2014-01-05
      • 2014-10-17
      • 1970-01-01
      • 2014-09-14
      • 2013-07-24
      • 1970-01-01
      • 2013-06-09
      • 2015-05-31
      • 2018-04-10
      相关资源
      最近更新 更多