OA项目拦截器代码报错,不知道是什么出了问题? 20C

网页报错如下:
type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.IllegalStateException
org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:876)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:567)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:233)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.45 logs.

myeclipse报错如下:
ERROR Dispatcher:38 - Exception occurred during processing request: Action has already executed
java.lang.IllegalStateException: Action has already executed
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:234)
at cn.hy.oa.interceptor.CheckPrivilegeInterceptor.intercept(CheckPrivilegeInterceptor.java:52)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:544)
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:233)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:612)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:503)
at java.lang.Thread.run(Thread.java:662)

拦截器具体代码:
/**

  • 进行权限检查的拦截器
  • @author Administrator
    *
    */
    public class CheckPrivilegeInterceptor extends AbstractInterceptor{

    /**

    • 拦截方法 */

    public String intercept(ActionInvocation ai) throws Exception {
    //System.out.println("自定义的拦截器执行了");

    //从Session中获取登录用户
    User user= (User) ServletActionContext.getRequest().getSession().getAttribute("loginUser");
    
    String actionName=ai.getProxy().getActionName();
    String namespace=ai.getProxy().getNamespace();
    String url=namespace +actionName;
    System.out.println("访问url" + url);
    
    // 一 ,用户没有登录
    if(user == null){
        // a 如果用户访问的是登录功能,则放行
        if("/user_login".equals(url)){
            ai.invoke();
        }else{
            // b 如果用户访问的不是登录功能,则跳转到登录页面
            return "loginUI";
        }
    
    }else{
        // 二, 用户已经登录
    
    }
    
    return ai.invoke();
    

    }
    }

2个回答

ai.invoke()调用了两次

你可以考虑把 return ai.invoke();这段代码放到else里面去的

}else{
// 二, 用户已经登录
return ai.invoke();
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问