zoukankan      html  css  js  c++  java
  • jsp自定义标签

    java类继承TagSupport

    /**
    * 输出两个数的和
    * @author sys
    *
    */
    public class TestTag extends TagSupport{

    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private int a ;
    private int b;
    public int getA() {
    return a;
    }
    public void setA(int a) {
    this.a = a;
    }
    public int getB() {
    return b;
    }
    public void setB(int b) {
    this.b = b;
    }

    public int doStartTag(){
    StringBuffer buffer = new StringBuffer("<div>");
    buffer.append(a+"+"+b+"="+"<strong>"+(a+b)+"</strong>");
    buffer.append("</div>");
    JspWriter out = pageContext.getOut();
    try {
    out.print(buffer.toString());//输出到页面
    out.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return SKIP_BODY;
    }


    }

    web-inf 下的tld文件

    <?xml version="1.0" encoding="UTF-8" ?>
    <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.1</tlib-version>
        <short-name>b</short-name>
        <uri>http://www.sys.com./testtag</uri>
        <tag>
            <name>s</name>
            <tag-class>com.sys.jsptag.TestTag</tag-class>
            <body-content>empty</body-content>
            <attribute>
                <name>a</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
                <type>int</type>
            </attribute>
            <attribute>
                <name>b</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
                <type>int</type>
            </attribute>
        </tag>
    
    </taglib>

    jsp页面调用

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="b" uri="http://www.sys.com./testtag" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>求和</title>
    </head>
    <body>

    <b:s b="2" a="2"/>
    </body>
    </html>

  • 相关阅读:
    C++------------------>深浅拷贝的问题
    超越 EfficientNet与MobileNetV3,NeurIPS 2020 微软NAS方向最新研究
    数学之美
    mobilenetV2--->特点
    安装R语言扩展包vegan
    每日积累新知识
    安装生物信息学软件-R
    安装生物信息学软件-MetaPhlAn2
    概率统计&假设检验-1
    Population-based metagenomics analysis reveals markers for gut microbiome composition and diversity
  • 原文地址:https://www.cnblogs.com/syscn/p/5798552.html
Copyright © 2011-2022 走看看