java - 在 doStartTag 函数中获取 JSP TLIB 的自定义标记名称

标签 java jsp tags taglib custom-tag

我需要在 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/

相关文章:

java - Hibernate Named Queries 是真正意义上的预编译吗?

java - 尝试使用 Alakai 插件将 Launch4j 集成到 Maven 项目中

javascript - 满足条件时进行网页抓取

html - ASP.NET MVC 如何将 html 标签显示为 html?

java - jdatechooser作为mysql查询中的参数

JavaFX 网格 Pane 和内容大小

javascript - jquery 对话框内的文本区域

mysql - 如何使用jxl将excel表格数据导入mysql数据库?

jquery - 将数据传递到 Bootstrap 模式

html - 使用 Angular2 的 HTML 标签中的变量