I did find that moving the session logic after all of the struts tags, it
worked.  I am still curious why it would not work in the original order,
since I was calling session = request.getSession(true); to make sure a new
session was available before the struts tags ran.

Does anyone have any insight about this?

-----Original Message-----
From: Ted Bergeron [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 19, 2001 5:17 PM
To: [EMAIL PROTECTED]
Subject: session.invalidate() - IllegalStateException


I am trying to implement a logout in my struts app.  I was using Tomcat 4.0
beta, but have moved to Resin 1.2.5. My problem occurs in both app servers.

The following code works fine until I reach the <html:html>.

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>

<%
    out.println("Session id is " + session.getId());
    if (!session.isNew()) {
        out.println("<H1>Your Session is OLD. I will invalidate it
here.</H1>");
        try {
            session.invalidate(); // They are here to login.  Kill any prior
sessions before login.
        } catch (IllegalStateException e) {
            out.println("<H1>I had an exception</H1>");
        }
    }

    try {
        session.setAttribute("lastPageAccessed", "Login");
    } catch (IllegalStateException e) {
        session = request.getSession(true);
        session.setAttribute("lastPageAccessed", "Login");
    }
%>


<%-- The following will cause:
500 Servlet Exception
java.lang.IllegalStateException: session is invalid
        at com.caucho.server.http.QSession.getAttribute(QSession.java:247)
        at org.apache.struts.taglib.html.HtmlTag.currentLocale(HtmlTag.java:219)
        at org.apache.struts.taglib.html.HtmlTag.doStartTag(HtmlTag.java:137)
        at _jsp._test__jsp._jspService(/test.jsp:30)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:87)
        at com.caucho.jsp.JavaPage.subservice(JavaPage.java:81)
        at com.caucho.jsp.Page.service(Page.java:407)
        at com.caucho.server.http.Invocation.service(Invocation.java:285)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:238)
        at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:157)
        at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
        at java.lang.Thread.run(Thread.java:484)
--%>

<html:html>
</html:html>

The code in the taglib reads:

----------
    protected Locale currentLocale() {

        // Create a new session if necessary
        HttpSession session = pageContext.getSession();
        if (locale && (session == null))
            session =
                ((HttpServletRequest)
pageContext.getRequest()).getSession();
        if (session == null)
            return (null);

        // Return any currently set Locale in our session
//Line 219:
      Locale current = (Locale) session.getAttribute(Action.LOCALE_KEY);


---------



Reply via email to