小编典典

使用Spring授权标签检查用户是否登录时出错?

jsp

尝试测试用户是否已登录,我正在使用以下代码:

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<sec:authorize access="isAuthenticated()">
   YES, you are logged in!
</sec:authorize>

但是我得到以下错误了吗?

javax.servlet.jsp.JspException: No visible WebSecurityExpressionHandler instance could be found in the application context. There must be at least one in order to support expressions in JSP 'authorize' tags.
        at org.springframework.security.taglibs.authz.AuthorizeTag.getExpressionHandler(AuthorizeTag.java:100)
        at org.springframework.security.taglibs.authz.AuthorizeTag.authorizeUsingAccessExpression(AuthorizeTag.java:58)
        at org.springframework.security.taglibs.authz.AuthorizeTag.doStartTag(AuthorizeTag.java:48)

阅读 358

收藏
2020-06-08

共1个答案

小编典典

要使用表达式保护单个URL,首先需要将元素中的use-expressions属性设置为true

<http use-expressions="true"> 参见Spring
Security文档

2020-06-08