![](/img/trans.png)
[英]How to customize the 403 Forbidden/Access Denied Page using Spring Security
[英]access denied page using spring security not working
我正在將以下配置用於拒絕訪問頁面
<security:access-denied-handler error-page="/noAccess"/>
然后將/ noAccess映射到控制器。 但是當我嘗試訪問我無權訪問的資源時,出現錯誤頁面
HTTP狀態404-瀏覽器中的/ mycontext / noAccess
雖然當我輸入整個URL http://abc.mycompany:8080 / mycontext / noAccess時,我可以看到錯誤頁面。 知道為什么spring不重定向到控制器嗎?
我正在為我的項目中的拒絕訪問頁面使用以下配置,它正在為我工作。
根據您的需要進行更改。
<security:http auto-config="true" use-expressions="true" access-denied-page="/accessDenied.jsp">
<security:form-login login-page="/index.jsp"
default-target-url="/jsp/home.jsp" />
<security:intercept-url pattern="/jsp/listInBetweenPlaces.jsp"
access="permitAll" />
</security:http>
將以下內容添加到您的bean配置中。
<mvc:view-controller path="/uncaughtException"/>
<mvc:view-controller path="/resourceNotFound"/>
<mvc:view-controller path="/dataAccessFailure"/>
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:defaultErrorView="uncaughtException">
<property name="exceptionMappings">
<props>
<prop key=".DataAccessException">dataAccessFailure</prop>
<prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
<prop key=".TypeMismatchException">resourceNotFound</prop>
<prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
</props>
</property>
</bean>
創建以下頁面並將其添加到Context文件夾
resourceNotFound.jsp
uncaughtException.jsp
dataAccessFailure.jsp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.