zoukankan      html  css  js  c++  java
  • JSP自定义标签之Hello Costom tag小例子

    1、项目结构

      

    2、实现自定义tag所需依赖

    <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
          <version>2.5</version>
          <scope>provided</scope>
        </dependency>
    
        <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>jsp-api</artifactId>
          <version>2.2</version>
          <scope>provided</scope>
        </dependency>

     3、HelloTag.java

    package com.tag;
    
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspWriter;
    import javax.servlet.jsp.tagext.SimpleTagSupport;
    import java.io.IOException;
    
    /**
     * Created by Administrator on 2016/7/11.
     */
    public class HelloTag extends SimpleTagSupport {
    
        @Override
        public void doTag() throws JspException, IOException {
            JspWriter out = getJspContext().getOut();
            out.println("Hello Custom Tag!");
        }
    }

    4、costom.tld

    <taglib>
        <tlib-version>1.0</tlib-version>
        <jsp-version>2.0</jsp-version>
        <short-name>Example TLD</short-name>
        <tag>
            <name>Hello</name>
            <tag-class>com.tag.HelloTag</tag-class>
            <body-content>empty</body-content>
        </tag>
    </taglib>

    5、index.jsp

    <%@ taglib prefix="ex" uri="../WEB-INF/custom.tld"%>
    <html>
    <body>
    <h2>Hello World!</h2>
    <form action="test1" method="post" id="form1">
        <input type="submit" name="submit" value="button">
    </form>
    <ex:Hello></ex:Hello>
    </body>
    </html>

    注:这里需要引入标签库

    <%@ taglib prefix="ex" uri="../WEB-INF/custom.tld"%>

    6、结果

      

  • 相关阅读:
    [bochs]反编译的代码只能参考参考
    [Linux命令]dd
    exp1orer.exe木马解除方法
    江民公布“密码7005”最新变种技术报告
    广外女生1次惊心动魄的卸载
    [病毒]exp1orer.exe
    [Win2003]禁用关机原因调查
    获得本机IP地址
    一段连接FTP的VC代码
    [Perl]FTP自动上传文件的脚本以及配置文件
  • 原文地址:https://www.cnblogs.com/sunjf/p/jsp_tag.html
Copyright © 2011-2022 走看看