I have the book "Professional JSP" (1st Edition).
Chapter 5 has some session management code that does not work.
I have searched the different newsgroups and tomcat archives, and have 
found where others have asked this question but I can't find where 
anyone has answered it.

The problem is that whenever "oldSession.invalidate()" is called; I get 
the following error message:

java.lang.IllegalStateException: getAttributeNames: Session already 
invalidated

I am using Tomcat 3.3, JDK 1.3.1_01 and Apache on RedHat Linux 7.2.

Here is the problem code:

-------------------

<%@ page language="java" import="java.util.*" errorPage="error1.jsp"%>

<jsp:useBean id="loginBean" scope="page" class="Login">
   <jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>

<jsp:useBean id="monitor" scope="application" class="java.util.HashMap"/>

<%
  String username = request.getParameter( "username" );
  String password = request.getParameter( "password" );
  loginBean.setUserName( username );
  loginBean.setPassword( password );

  String display = "index.html";
  User user = loginBean.authenticate();
  if( user != null ){
    user.setIPAddr(request.getRemoteHost());
    // Got user.  Do they already have a session?
    if( monitor.containsKey(user)){
      // There's an old session for this user - invalidate it
      HttpSession oldSession = (HttpSession)monitor.get(user);
      String sID1 = oldSession.getId();
      System.out.println("Existing Session detected: " + sID1);
      oldSession.invalidate();
    }

    session.setAttribute("user", user);
    monitor.put(user, session);
    String sID = session.getId();
    System.out.println("Session Created: " + sID);

    session.setMaxInactiveInterval(300);

    display="browse.jsp";
  }
%>

<jsp:forward page="<%= display %>"/>

----------------

Any help greatly appreciated.

Thanks,

Rick Roberts


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to