Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 创建简单的自定义标记以显示或隐藏主体_Java_Jsp_Jsp Tags - Fatal编程技术网

Java 创建简单的自定义标记以显示或隐藏主体

Java 创建简单的自定义标记以显示或隐藏主体,java,jsp,jsp-tags,Java,Jsp,Jsp Tags,我正在尝试创建自己的自定义标记,以便根据属性集显示或隐藏标记之间的内容 <mytag:isUserInRole role="admin">Show admin specific text</mytag:isUserInRole>` 下面是我的AuthorizationTag doStartTag方法: public int doStartTag() throws JspException{ System.out.println("Role"+role);

我正在尝试创建自己的自定义标记,以便根据属性集显示或隐藏标记之间的内容

<mytag:isUserInRole role="admin">Show admin specific text</mytag:isUserInRole>`
下面是我的AuthorizationTag doStartTag方法:

    public int doStartTag() throws JspException{
    System.out.println("Role"+role);

    //Check that role is given and securitycontext is not null
    if(role==null|| SecurityContextHolder.getContext()==null || SecurityContextHolder.getContext().getAuthentication()==null){
        return Tag.SKIP_BODY;
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if(hasPermission(auth)){
        return Tag.EVAL_BODY_INCLUDE;
    } else {
        return Tag.SKIP_BODY;
    }
}

试试这个:
jsp
,还要注意
之间的区别,因为我知道有一个
标记库uri=”http://www.springframework.org/security/tags“
哪一个正是您想要实现的目标-它有

谢谢!工作起来很有魅力:)请注意,Facelets与JSP不同,因此标记处理程序可能不完全相同。是的,我正在调查这个问题,但我找不到任何关于如何根据需要使用它的文档,所以我决定实现我自己的解决方案。。。
    public int doStartTag() throws JspException{
    System.out.println("Role"+role);

    //Check that role is given and securitycontext is not null
    if(role==null|| SecurityContextHolder.getContext()==null || SecurityContextHolder.getContext().getAuthentication()==null){
        return Tag.SKIP_BODY;
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if(hasPermission(auth)){
        return Tag.EVAL_BODY_INCLUDE;
    } else {
        return Tag.SKIP_BODY;
    }
}