title: IllegalStateException in websphere when invalidating session
body: <p>I want to invalidate a session when a jsp is loaded so that any existing session attributes are removed from jsp which is directing to this jsp.Below code is working on tomcat6.0.29 but throwing java.lang.IllegalStateException in websphere7.0.19.I have tried adding few 'if' conditions but it throws error when invalidate is invoked.</p>
  
  <pre><code>&lt;%
        try {                 
                  if(request.getSession().getAttribute("userId") != null)
                  {
  
                      if (!request.getSession().isNew()) {
                          request.getSession().invalidate();
                      }
                  }
                  } catch (Exception ex) {System.out.println("catch");
                  }
   %&gt;
  </code></pre>
  
  <p>Error msg</p>
  
  <pre><code>00000032  E UOW=null source=com.ibm.ws.webcontainer.servlet class=com.ibm.ws.webcontainer.servlet.ServletWrapper method=service org=null prod=null component=null thread=[WebContainer : 7]
        SRVE0068E: Uncaught exception created in one of the service methods of the servlet /jsp/login.jsp in application xxxxxxxx. Exception created : java.lang.IllegalStateException
  at com.ibm.ws.session.http.HttpSessionImpl.getAttribute(HttpSessionImpl.java:191)
  at com.ibm.ws.session.SessionData.getSessionValue(SessionData.java:306)
  at com.ibm.ws.session.SessionData.getAttribute(SessionData.java:162)
  at com.ibm.ws.session.HttpSessionFacade.getAttribute(HttpSessionFacade.java:139)
  at org.apache.jasper.runtime.PageContextImpl.findAttribute(PageContextImpl.java:435)
  at javax.servlet.jsp.el.ScopedAttributeELResolver.getValue(ScopedAttributeELResolver.java:89)
  at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
  at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
  at org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:29)
  at org.apache.el.parser.AstNot.getValue(AstNot.java:26)
  at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:263)
  at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:774)
  at com.ibm._jsp._login._jspx_meth_c_if_0(_login.java:191)
  at com.ibm._jsp._login._jspService(_login.java:163)
  at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:104)
  at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
  at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934)
  at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
  at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
  at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
  at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:259)
  at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:354)
  at com.ibm.ws.webcontainer.servlet.FilterProxyServlet.dispatch(FilterProxyServlet.java:88)
  at com.ibm.ws.webcontainer.servlet.FilterProxyServlet.service(FilterProxyServlet.java:62)
  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
  at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413)
  at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
  at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:997)
  at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.invokeFilters(DefaultExtensionProcessor.java:1062)
  at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:759)
  at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3935)
  at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
  at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
  at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
  at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
  at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
  at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
  at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
  at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
  at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
  at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
  at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
  at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
  at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
  </code></pre>
  
  <p><strong>Issue resolved</strong>- we have been able to resolve the issue by adding &lt;%@page session="false"%> in JSPs and explicitly defining the session in both JSPs
  <a href="https://stackoverflow.com/questions/18929718/session-invalidate-not-working-in-websphere-application-server">session.invalidate() not working in Websphere Application Server</a></p>
  
  <pre><code>try {   
  
                  HttpSession session = request.getSession();
  
                  if(session!=null)
                  {session.invalidate();}
                  } catch (Exception ex) {
                  }
  </code></pre>