我有一个受保护的页面,应该在未登录时重定向到登录屏幕。问题是,当我尝试查看该页面时,它不会重定向到登录,而是因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-config文件
<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>
所以只是总结一下。首次访问浏览器启动时受保护的页面,它崩溃而不是重定向到登录。我手动访问登录页面,然后尝试访问受保护的页面没有崩溃,它重定向回登录就像它应该的那样。它将继续正常工作,直到我重新启动浏览器。
任何想法??
答案 0 :(得分:3)
此问题已解决。我完全不知道为什么,但是当我更改我的struts xml文件以使用这个DTD文件时
http://struts.apache.org/dtds/struts-2.3.dtd
而不是
问题消失了。我正在抓住秸秆检查每个配置文件与我拥有的其他应用程序的配置文件,使用相同的过程没有问题,看到了这一点。我决定了什么,并做出了改变......它的确有效。