开发者

Can a JSP tag access the JSP page instance that contains it?

开发者 https://www.devze.com 2023-02-27 00:37 出处:网络
If a page contains JSP-tag, can the tag access the instance of the JSP class that it is being used in?

If a page contains JSP-tag, can the tag access the instance of the JSP class that it is being used in?

Assume we have the following JSP:

<%
    String someVariable;
%>

    Hello <ns:开发者_JAVA百科someTag />

Can someTag's class access the value of someVariable?


No, because the usage of tags and scriptlets should not be mixed.

If you define the 'variable' as a request attribute, with jstl: <c:set var="someVar" value"foo" />, then it is accessible via the pageContext in the Tag class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号