基于网址禁用导航栏元素

问题描述 投票:-1回答:1

我接手了一个项目。并且有一个导航栏可以导航到其他站点。

此带有导航栏的文件包含在每个文件中。到目前为止,这没有问题。

但是现在我将添加一个名为“ Holiday”的新元素。这仅应在特定的URL上可见。

对于以/ user / ..开头的URL应该是可见的,但对于以/ admin / ..开头的URL则不可见。

有没有办法做到这一点?顺便说一下,这个项目是用jsp完成的。它是几年前完成的。但如果Thymeleaf有可能,我也会感兴趣。

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
            <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <a class="navbar-brand fa fa-home fa-2x" style="color: darkblue; font-size: 20px" href="<c:url value="/user/workingtimeNow"/>">Home</a>
            <sec:authorize access="hasAnyRole('ROLE_ADMIN', 'ROLE_MANAGER')">
            <a class="navbar-brand fa fa-cog fa-2x" style="color: darkblue; font-size: 20px" href="<c:url value="/manager/home"/>">Admin</a>
            </sec:authorize>
            <a class="navbar-brand fa " style="color: darkblue; font-size: 20px" href="<c:url value="/user/workingtimeNow"/>">Holiday</a>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
jsp thymeleaf
1个回答
0
投票

您可以使用此方法检索URI(请求的URL中主机名后面的部分:]

String uri = request.getRequestURI()

然后,基于此“ uri”字符串内容(例如包含“ / admin /”或不包含)进行if / then测试...

亲切的问候,

© www.soinside.com 2019 - 2024. All rights reserved.