Spring security 具有spring安全性的Sitemesh未重定向到目标url

Spring security 具有spring安全性的Sitemesh未重定向到目标url,spring-security,sitemesh,Spring Security,Sitemesh,我正在将spring安全性与使用sitemesh的web项目集成。我能够带来登录页面,但经过身份验证后,它不会重定向到目标url 下面是web项目中的web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

我正在将spring安全性与使用sitemesh的web项目集成。我能够带来登录页面,但经过身份验证后,它不会重定向到目标url

下面是web项目中的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<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>

<context-param>
   <param-name>contextConfigLocation</param-name>
      <param-value>
    classpath:applicationContext-persistance.xml
    classpath*:applicationContext.xml
    classpath:spring-security.xml
        </param-value>
</context-param>

<listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
  <servlet-name>appServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<!--    
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/*.app</url-pattern>
</servlet-mapping>
-->
<!-- <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/index.html</url-pattern>
</servlet-mapping> 
-->

<!-- Sitemesh -->
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>
         com.opensymphony.module.sitemesh.filter.PageFilter
    </filter-class>
</filter>

<!-- <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/app/*</url-pattern>
</filter-mapping> -->

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!--<welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>-- > 
</web-app>
所以这里的问题是访问url-,它显示登录页面。成功验证后,它将尝试重定向到。不确定为什么会发生这种情况,而不是默认目标url中提到的/index.html

来自tomcat的日志行显示-

DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for
 [/acct/login]
DEBUG: org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapping [/login] to HandlerExecutionCh
ain with handler [com.mycomp.security.controller.LoginController@1e5348f] and 2 interceptors
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/acct/login] is: -1
DEBUG: org.springframework.web.bind.annotation.support.HandlerMethodInvoker - Invoking request handler method: public java.lan
g.String com.mycomp.security.controller.LoginController.login(org.springframework.ui.ModelMap)
DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name
 'loginpage'; URL [/WEB-INF/views/loginpage.jsp]] in DispatcherServlet with name 'appServlet'
DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/loginpage.jsp] in InternalResour
ceView 'loginpage'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for
 [/acct/app]
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/acct/app] in DispatcherServ
let with name 'appServlet'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for
 [/acct/app]
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/acct/app] in DispatcherServ
let with name 'appServlet'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
通过将DispatcherServlet映射更改为/而不是/index.html,尝试了大量调试。将sitemesh筛选器映射更改为/*而不是/index.html。 如果与示例web项目(没有sitemesh)集成,相同的AppSecurity项目也可以正常工作。 不确定我在sitemesh项目中缺少了什么。这里的任何帮助都很好。

“默认目标url=/index.html”
这将在您成功登录后重定向页面。 例如,您可以重定向到
/home.html
或使用控制器中的
/home.do
执行一些逻辑操作,然后再重定向到所需页面

@RequestMapping(value = "/home.do", method = RequestMethod.POST)
public String login(ModelMap model) {

   //TODO logic ...
   return "/home.html";
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(ModelMap model) {
   return "loginpage";
}
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for
 [/acct/login]
DEBUG: org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapping [/login] to HandlerExecutionCh
ain with handler [com.mycomp.security.controller.LoginController@1e5348f] and 2 interceptors
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/acct/login] is: -1
DEBUG: org.springframework.web.bind.annotation.support.HandlerMethodInvoker - Invoking request handler method: public java.lan
g.String com.mycomp.security.controller.LoginController.login(org.springframework.ui.ModelMap)
DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name
 'loginpage'; URL [/WEB-INF/views/loginpage.jsp]] in DispatcherServlet with name 'appServlet'
DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/loginpage.jsp] in InternalResour
ceView 'loginpage'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for
 [/acct/app]
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/acct/app] in DispatcherServ
let with name 'appServlet'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for
 [/acct/app]
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/acct/app] in DispatcherServ
let with name 'appServlet'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
@RequestMapping(value = "/home.do", method = RequestMethod.POST)
public String login(ModelMap model) {

   //TODO logic ...
   return "/home.html";
}