1

我需要在 doStartTag 函数中获取请求者标签的名称我在 .tld 中有这个自定义标签

<tag>
    <name>Resource</name>
    <tag-class>Mirnint.Interface.Tag.MNIT_Resources</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <name>Style</name>
        <required>false</required>
    </attribute>
    <attribute>
        <name>JavaScript</name>
        <required>false</required>
    </attribute>
</tag>

在 JSP 中:-

<%@ taglib uri="/webapp/Min" prefix="Min"%>
<html>
<head>
    <Min:Resource/>
</head>

和java类是: -

@Override
public int doStartTag() throws JspException {
//Here i need to print the name of caller tag in this example it should be ("Resource")...
System.out.println(**The Name of Tag**);
}

你的输出应该是

Resource

感谢帮助...

4

1 回答 1

0

您需要创建一个与名称对应的getter/setter;那么你的代码会是这样的:

public class Hello extends TagSupport {
    private String name=null;
    /**
      * Getter/Setter for the attribute name as defined in the tld file 
      * for this tag
      */
public void setName(String value){
    name = value;
}

    public String getName(){
          return(name);
       }
/**
* doStartTag is called by the JSP container when the tag is encountered
*/
    public int doStartTag() {
    System.out.println(name);
    }
于 2013-09-12T11:56:01.437 回答