春天的安全。授权不适用于jsp

时间:2014-12-07 15:58:13

标签: java jsp spring-security

我有跟随jsp页面并且jsp按预期编译

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>

<c:if test="${sessionScope.userName!=null}">

    ...

</c:if>

在登录控制器方法中,我有以下行:

session.setAttribute("userName", name);

我认为最好使用spring security tags重写它

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>

<sprSec:authorize access="isAuthenticated()">

  ...

</sprSec:authorize>

现在我在尝试访问页面时遇到以下错误:

  org.apache.jasper.JasperException: org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/*/*****.jsp at line 5

    2: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    3: <%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>
    4: 
    5: <sprSec:authorize access="isAuthenticated()">
    6: 
    7: <c:set var="profileUrl" value="#" scope="request" />
    8:  <sprSec:authorize ifAllGranted="ROLE_USER">


....

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: java.io.IOException: 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.
..........

1 个答案:

答案 0 :(得分:2)

这可能是Spring Security - No visible WebSecurityExpressionHandler instance could be found in the application context的副本。

如前所述,请务必为配置的use-expressions元素添加http属性设置为true,即写<http use-expressions="true">

相关问题