yangkaikai
yangkaikai
2009-10-22 16:25

SSH的项目中有没有判断session是否为空的过滤器之类的东西

  • 设计模式

SSH的项目中,如何统一判断session是否为空,项目中很多操作都需要登录后才能执行,不想在每个action中都写判断session是否为空的语句,有没有什么拦截器,或者spring的什么配置可以搞定这个的?
[b]问题补充:[/b]
写了个struts2 的拦截器,代码如下:
@Override
public String intercept(ActionInvocation arg0) throws Exception {
Logger logger = Logger.getLogger(this.getClass());
// TODO Auto-generated method stub
Corp corp = (Corp)ActionContext.getContext().getSession().get("corp");
if(corp==null){

        logger.info("strus 拦截器 corp 为空");
        return "none";
    }
    logger.info("struts 拦截器 invoke:返回"+arg0.invoke());      
    return arg0.invoke();   
}

结果出现了个异常如下:

java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:725)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76)
at com.cool.filter.MyFilter.doFilter(MyFilter.java:61)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
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 com.cool.filter.MyCharacterEncodingFilter.doFilterInternal(MyCharacterEncodingFilter.java:58)
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:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
[b]问题补充:[/b]
哪个能帮忙搞定,不明白为什么会和struts2的过滤器相关,myfilter是我自己的过滤器,集成struts2的过滤器。试过了只要去掉拦截器就不会出现这个错误。
[b]问题补充:[/b]
蔡华江同学,还是一样的错误哦,这个和session没有什么关系吧,网上都说是调用了两次response,我很费解,如果没有登录返回none的时候没有错误,登录后session不为空了反倒出了这个错误,你再帮我看看吧,我实在搞不定了,我看好你哦。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

6条回答