时间:2021-05-26
在sun官方文档上有下面这样一段话。
官方文档声明
public interface SimpleTagextends JspTagInterface for defining Simple Tag Handlers.Simple Tag Handlers differ from Classic Tag Handlers in that instead of supporting doStartTag() and doEndTag(), the SimpleTag interface provides a simple doTag() method, which is called once and only once for any given tag invocation. All tag logic, iteration, body evaluations, etc. are to be performed in this single method. Thus, simple tag handlers have the equivalent power of BodyTag, but with a much simpler lifecycle and interface.To support body content, the setJspBody() method is provided. The container invokes the setJspBody() method with a JspFragment object encapsulating the body of the tag. The tag handler implementation can call invoke() on that fragment to evaluate the body as many times as it needs.A SimpleTag handler must have a public no-args constructor. Most SimpleTag handlers should extend SimpleTagSupport.生存周期及调用流程
The following is a non-normative, brief overview of the SimpleTag lifecycle. Refer to the JSP Specification for details.
A new tag handler instance is created each time by the container by calling the provided zero-args constructor. Unlike classic tag handlers, simple tag handlers are never cached and reused by the JSP container.
The setJspContext() and setParent() methods are called by the container. The setParent() method is only called if the element is nested within another tag invocation.
The setters for each attribute defined for this tag are called by the container.
If a body exists, the setJspBody() method is called by the container to set the body of this tag, as a JspFragment. If the action element is empty in the page, this method is not called at all.
The doTag() method is called by the container. All tag logic, iteration, body evaluations, etc. occur in this method.
The doTag() method returns and all variables are synchronized.
简单标签使用小案例
必知必会:简单标签也是一个标签,所以声明的过程也Tag的一样,同样是三步。
1、建继承SimpleTag类的实现类,重写doTag方法
2、tld文件中进行严格的声明
3、jsp页面中taglib的命名空间及标签前缀的声明,然后进行调用自定义的简单标签
第一步:创建实现类:
在tld文件中进行相关约束项的配置:
第三步:在jsp页面中进行声明然后调用:
总结:
简单标签可以替代BodyTag接口完成同样的操作,但是有更加的简单和轻便
简单标签lifeCycle逻辑清晰,调用规则明确
使用相关流对象就可以完成对标签体的操控maniplate
以上就是本文的全部内容,希望对大家的学习有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文为大家分享了JSP自定义标签入门学习教程,希望大家喜欢。1.JSP自定义标签:自定义标签是用户定义的JSP语言元素。当JSP页面包含一个自定义标签时将被转化
一、自定义标签入门之无参数自定义标签1.开发自定义标签类当我们在JSP页面使用一个简单的标签时,底层实际上由标签处理类提供支持,从而可以使用简单的标签来封装复杂
本文实例讲述了jsp中自定义标签用法。分享给大家供大家参考。具体如下:这里简单的写了一个自定义标签,自己定义标签的好处就是在jsp页面中可以使用自己定义的功能,
本文实例讲述了javaWeb自定义标签用法。分享给大家供大家参考,具体如下:自定义标签创建自定义标签主要用于移除Jsp页面中的Java代码。移除jsp页面中的j
在JSP中使用自定义标签可以达到这样的目的,事实上,我们所熟知的各类框架基本上都是通过自定义标签的形式来实现的。通过使用自定义标签,我们可以将实现复杂的逻辑在页