我需要在 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
感谢您的帮助...
最佳答案
需要创建一个name对应的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);
}
关于java - 在 doStartTag 函数中获取 JSP TLIB 的自定义标记名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18763130/