JSTL标签库

2017-01-08  本文已影响13人  大批

JSTL


Core (c标签)


fmt (格式化标签)


SimpleTag || SimpleTagSurport

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;
    }
}
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
  version="2.0">
 <tlib-version>1.0</tlib-version>
 <short-name>hellotag</short-name>
 <uri>http://www.suse.yuxin/tags/1.0</uri>
 
 <tag>
    <name>hellotag</name>
    <tag-class>com.suse.yuxin.tags.TestSimpleTag</tag-class>
    <body-content>empty</body-content>
 </tag>
 
</taglib>
<%@ taglib prefix="mm" uri="/WEB-INF/tlds/hellotag.tld" %>
<mm:hellotag/>

标签体内容

标签的属性

</tag>


- - -

> 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**

# :)



上一篇下一篇

猜你喜欢

热点阅读