java – 当传入null时,JSP标记属性从父作用域继承变量?

我最近遇到一个问题,即将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,但在标记模型中不是null,它实际上解析为模型在JSP中表示的对象!如果有帮助,我正在使用Spring MVC 3.

解决方法

你确定JSP中的${model.testModel}是空的吗?您是否尝试过传入变量的语法:
<jsp:directive.attribute name="model" type="com.example.test.model.component.TestModel" required="true" rtexprvalue="true" />

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...