(三)TagtSupport类简介

 TagtSupport类简介

TagSupport类主要属性介绍

A.parent属性:代表嵌套了当前标签的上层标签的处理类

B.pageContex属性:代表Web应用中javax.servlet.jsp.PageContext对象

 

TagSupport添加自定义属性


在使用自定义标签时,通常会希望在标签中使用一些属性值来达到不同的显示效果。可在TagSupport类中添加属性并用get/set方法来实现。

如下面的示例
TagSupport类中
public class DemoViewTag extends TagSupport {
 private static final long serialVersionUID = 1L;
 private String northTitle = "";
 private String westTitle = ""; 
 public String getNorthTitle() {
  return northTitle;
 }
 public void setNorthTitle(String northTitle) {
  this.northTitle = northTitle;
 }
 public String getWestTitle() {
  return westTitle;
 }
 public void setWestTitle(String westTitle) {
  this.westTitle = westTitle;
 }
JSP页面使用时:<myTag:demo.Viewport northTitle="南" westTitle="西"></myTag:demo.Viewport>

 

TagSupport主要方法


(一)setPageContext(),setParent():Web容器会在doStartTag方法和doEndTag方法前调用setPageContext和setParent方法,所以可以在重写这两个方法用来设置类中共有的字。如下面的示例代码
 @Override
 public void setPageContext(PageContext pageContext) {
  // TODO Auto-generated method stub
  properties=(Properties)pageContext.getServletContext().getAttribute("tagProperties");
  super.setPageContext(pageContext);
 }
(二)doStartTag():当Web容器遇到自定义标签的起始标志时就会调用doStartTag方法,其通常的返回一个整数值用于决定后续的处理流程。通常有两种值:
 super.SKIP_BODY:表示自定义标签体的Body内容将不被显示
 super.EVAL_BODY_INCLUDE:表示Body内容将显示
(三)doEndTag():当Web容器遇到自定义标签的起始标志时就会调用doStartTag方法,其通常的返回一个整数值用于决定后续的处理流程。通常有两种值:
 super.EVAL_PAGE:表示将按正常流程执行JSP页面
 super.SKIP_PAGE:表示将立即停止执行JSP页面

你可能感兴趣的:(Web,jsp,String,properties,Class,include)