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);
---------