Java – when null is passed in, the JSP tag attribute inherits the variable from the parent scope?
•
Java
I recently encountered a problem that passing null to a custom JSP tag will cause the tag to move up the scope and resolve the variable to a variable with the same name in the parent JSP
This is expected in Java / JSP / JSTL. Is there any way to override this function without renaming variables without naming conflicts?
For example, a JSP file:
<%@ 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>
Call this tag file (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}"/>
What I see is that although the model Testmodel is null in JSP, but not null in tag model. It actually resolves to the object represented by the model in JSP! If it helps, I'm using spring MVC 3
Solution
Are you sure ${model. Testmodel} in JSP is empty? Have you ever tried the syntax of an incoming variable:
<jsp:directive.attribute name="model" type="com.example.test.model.component.TestModel" required="true" rtexprvalue="true" />
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码