如何检查用户在JSP中是否具有某个角色?

时间:2020-12-03 16:48:15

I need to make decisions in a JSP based on the user's roles. Is there a tag or EL expression that lets me do that?

我需要根据用户的角色在JSP中做出决策。是否有标签或EL表达式可以让我这样做?

1 个解决方案

#1


There isn't one built into JSP or JSTL, but the request taglib from the Jakarta project provides an isUserInRole tag. Install the taglib, and use the tag like this:

JSP或JSTL中没有内置的,但来自Jakarta项目的请求taglib提供了一个isUserInRole标记。安装taglib,并使用如下标记:

<req:isUserInRole role="admin">
 The remote user is in role "admin".
</req:isUserInRole>
<req:isUserInRole role="admin" value="false">
 The remote user is not in role "admin".
</req:isUserInRole>

#1


There isn't one built into JSP or JSTL, but the request taglib from the Jakarta project provides an isUserInRole tag. Install the taglib, and use the tag like this:

JSP或JSTL中没有内置的,但来自Jakarta项目的请求taglib提供了一个isUserInRole标记。安装taglib,并使用如下标记:

<req:isUserInRole role="admin">
 The remote user is in role "admin".
</req:isUserInRole>
<req:isUserInRole role="admin" value="false">
 The remote user is not in role "admin".
</req:isUserInRole>