【问题标题】:JSP tag attribute inherits variable from parent scope when null is passed in?传入null时,JSP标记属性从父范围继承变量?
【发布时间】:2013-12-23 01:58:55
【问题描述】:

我最近遇到了一个问题,将null 传递到自定义 JSP 标记导致标记上升范围并将变量解析为父 JSP 中的同名变量。

这在 Java/JSP/JSTL 中是预期的吗?是否有任何方法可以覆盖此功能而不必重命名我的变量以避免命名冲突?

例如,一个 JSP 文件:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="component" uri="http://www.example.com/test/component"%>

<component:testTag model="${model.testModel}"></component:testTag>

调用这个标签文件(testTag.tag):

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ attribute name="model" required="true" rtexprvalue="true" type="com.example.test.model.component.TestModel" %>

Is model empty? <c:out value="${empty model}"/>

我看到的是,尽管 model.testModel 在 JSP 中为 null,但标签中的 modelnot null 并且它实际上解析为 model 在JSP!?如果有帮助,我正在使用 Spring MVC 3。

【问题讨论】:

    标签: java jsp jstl jsp-tags


    【解决方案1】:

    您确定 JSP 中的 ${model.testModel} 为空吗?您是否尝试过这种传递变量的语法:

    <jsp:directive.attribute name="model" type="com.example.test.model.component.TestModel" required="true" rtexprvalue="true" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-18
      • 2022-09-27
      • 1970-01-01
      • 2014-07-26
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多