0

我有一个受保护的页面,在未登录时应该重定向到登录屏幕。问题是,当我尝试查看该页面时,它没有重定向到登录,而是因 IllegalStateException 错误而崩溃。更重要的是,如果我手动访问它加载的登录页面,那么我会尝试再次访问保护页面,它会按预期重定向。这一定是某种会话缓存问题,因为除非我重新启动浏览器,否则该问题将永远不会再次发生。重新启动浏览器后,问题将继续存在,直到我再次手动访问登录页面。当然,错误报告对于问题的实际情况非常模糊

Aug 20, 2013 4:36:40 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:852)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:127)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

我用来验证他们是否已登录并在必要时重定向的拦截器。第一次return BaseAction.Login点击就像它应该的那样,当我启用日志记录时,struts2 记录器表明重定向到 viewLogin 将会发生,但它没有。我只是崩溃了:

public String intercept(ActionInvocation invocation) throws Exception {
    BaseAction action = (BaseAction)invocation.getAction();
LoginManager loginManager = (LoginManager)action.getSession().get("loginManager");
Boolean loggedIn = false;

    final ActionContext context = invocation.getInvocationContext(); 
    ActionMapping mapping = (ActionMapping)context.get(ServletActionContext.ACTION_MAPPING);


        if(loginManager == null && action.isLoginRequired()) {
            //user is not logged in and login required, redirect them to login module
            return BaseAction.LOGIN;
        } else if(loginManager != null && action.isLoginRequired()) {
            //logged in, make sure they are accessing a valid resource
            String loginKey = action.getSessionLoginVarable(mapping);
            if(loginManager.getLoginPaths().containsKey(loginKey)) {
                return invocation.invoke();
            } else {
                //return to login which will redirect them to appropriate path
                return BaseAction.LOGIN;
            }
        } else {
            //public access to continue with action
            return invocation.invoke();
        }
}

Struts 配置文件

<package name="student" namespace="/student" extends="struts-default-custom">
    <default-action-ref name="viewLogin" />
    <global-results>
        <result name="login" type="redirectAction">viewLogin</result>
    </global-results>

    <action name="*Login" method="{1}" class="controller.shared.StudentLogin">
        <interceptor-ref name="noLoginStack"/>

        <result type="redirectAction">viewSearchAdvisors</result>
        <result name="input">/student/student-login.jsp</result>
        <result name="error" type="redirectAction">viewLogin</result>
    </action>

所以简单总结一下。在浏览器启动时首次访问此受保护页面时它会崩溃而不是重定向到登录。我手动访问登录页面,然后尝试访问受保护的页面而不会崩溃,它会像预期的那样重定向回登录。它将继续正常工作,直到我重新启动浏览器。

有任何想法吗??

4

1 回答 1

3

此问题已解决。我完全不知道为什么,但是当我更改我的 struts xml 文件以使用这个 DTD 文件时

http://struts.apache.org/dtds/struts-2.3.dtd

代替

http://struts.apache.org/dtds/struts-2.1.dtd

问题消失了。我正在抓住稻草检查每个配置文件与其他应用程序的配置文件,这些应用程序使用相同的过程没有问题,并看到了这一点。我决定了到底是什么并做出了改变……它奏效了。

于 2013-08-22T01:01:39.143 回答