JSTL标签库

JSTL

  • apache对EL表达式的扩展
  • jstl.jar包
    • core 核心库
    • fmt 格式化标签库

Core (c标签)

  • out && set

    • // ${xxx}
    • // 默认true

    • // scope默认pageContext
  • remove

    • //所有域的变量
  • url (路径前面自动加上项目名)

    • //必须以斜杠开头
    • 子标签 url后面添加参数
      • // value会有url编码
  • if



  • choose





  • forEach



    • ${item}
  • 循环状态


  • ${vs.index} ${vs.count} ${vs.first} ${vs.last}


fmt (格式化标签)


SimpleTag || SimpleTagSurport

  • void doTag() //每次执行
  • void setJspBody(JspFragment jspBody)
  • void setJspContext(JspContext context)
  • JspTag getParent() //设置标签体
  • void setParent(JspTag parent)

eg:


package com.suse.yuxin.tags;
import java.io.IOException;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.JspTag;
import javax.servlet.jsp.tagext.SimpleTag;
   
public class TestSimpleTag implements SimpleTag {
    @Override
    public void doTag() throws JspException, IOException {
      context.getOut().write("Hello tags");
    }

    @Override
    public JspTag getParent() {
        return parent;
    }

    @Override
    public void setJspBody(JspFragment jspBody) {
        this.fragment = jspBody;
    }
    
    
    private JspTag parent;
    private JspContext context;
    
    private JspFragment fragment;
    
    
    @Override
    public void setJspContext(JspContext pc) {
        this.context = pc;
    }

    @Override
    public void setParent(JspTag parent) {
        this.parent = parent;
    }
}

 1.0
 hellotag
 http://www.suse.yuxin/tags/1.0
 
 
    hellotag
    com.suse.yuxin.tags.TestSimpleTag
    empty
 
 

<%@ taglib prefix="mm" uri="/WEB-INF/tlds/hellotag.tld" %>

标签体内容

  • empty
  • scriptless 只能是EL表达式 或者其他标签 // ${el}

标签的属性

  • 标签处理类至少要有一个set方法
  • 在tld里面配置属性
     
      hellotag
      com.suse.yuxin.tags.TestSimpleTag
      empty
      
          test
          false
          true 
      
    


- - -

> Nothing is certain in this life. The only thing i know for sure is that. I love you and my life. That is the only thing i know. **have a good day**

# :)



你可能感兴趣的:(JSTL标签库)