解决Tomcat的java.lang.IllegalStateException: Cannot create a session after the response has been committed问题

0x00

  level: 0x04

0x01

  code:

           try {// TOMCAT 下将原 sessionId 赋值给新 request
                    if (request instanceof org.apache.catalina.connector.RequestFacade) {
                        java.lang.reflect.Field field = org.apache.catalina.connector.RequestFacade.class.getDeclaredField("request");
                        field.setAccessible(true);
                        org.apache.catalina.connector.Request r = (org.apache.catalina.connector.Request) field.get(request);
                        r.setRequestedSessionCookie(true);
                        r.setRequestedSessionId(request.getSession().getId());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

0x02

  PS: 感觉这样子,吊爆了。这问题情况很复杂,这种方法对其他的项目不一定有效

posted @ 2015-03-18 11:57  _峰_  阅读(8795)  评论(0编辑  收藏  举报