我在互联网上尝试了很多解决方案,但我无法访问login.jsp文件中的资源包。我的应用程序配置了弹簧安全性。
我尝试通过spring控制器路由登录页面,这样我就可以访问JSP中的资源包了但是我得到了无限循环..
这是我的spring-security.xml文件
<sec:global-method-security pre-post-annotations="enabled" />
<sec:http pattern="/css/**" security="none"/>
<sec:http pattern="/images/**" security="none"/>
<sec:http pattern="/js/**" security="none"/>
<sec:http pattern="/index.jsp" security="none"/>
<!-- <sec:http pattern="/app/addNewUser.json" security="none"/> -->
<sec:http pattern="/app/login.jsp" security="none"/>
<sec:http use-expressions="true">
<!--
Allow all other requests. In a real application you should
adopt a whitelisting approach where access is not allowed by default
-->
<sec:intercept-url pattern="/**" access="isAuthenticated()" />
<sec:form-login login-page='/app/login.jsp'
authentication-failure-url="/app/login.jsp?login_error=1"
default-target-url="/index.jsp" />
<sec:logout logout-success-url="/app/login.jsp" delete-cookies="JSESSIONID"/>
<sec:remember-me />
我正在尝试使用<spring:message code="login.name" />
访问资源包但我收到错误
No message found under code 'login.name' for locale 'en_US'.
这是web.xml条目
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Spring3MVC</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-rootcontext.xml
/WEB-INF/spring-security-no-cas.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
- Loads the root application context of this web app at startup.
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CAS Single Sign Out Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
</listener>
</web-app>
让我知道任何解决方案..
答案 0 :(得分:0)
重定向登录到Spring MVC解析的页面,例如; /login.htm - 假设“htm”映射到Spring MVC调度程序。
...
<sec:form-login login-page='/login.htm'
authentication-failure-url="/login.htm?login_error=1"
default-target-url="/index.htm" />
<sec:logout logout-success-url="/login.htm" delete-cookies="JSESSIONID"/>
...
然后为该URL
定义一个视图解析器<mvc:view-controller path="/login.htm" view-name="<where-jsp-are-stored>/app/login.jsp"/>
您应该能够解决消息。