I'm getting an exception in Tomcat 4.0.3 that I don't know what to do with.
I'm reading James Goodwill's book "Apache Jakarta-Tomcat" and I'm trying to
run the example
On page page 128.  I'm using Mysql and session data shows up in the database
some of the time, other times Tomcat throws the exception. I'm new to this,
sorry for posting all the code, but I have been working on this for 3 days.
Tim


The exception I'm getting is
java.io.IOException: Stream closed
        at
java.io.BufferedInputStream.ensureOpen(BufferedInputStream.java:123)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:273)
        at
java.io.ObjectInputStream.readFullyInternal(ObjectInputStream.java:1780)
        at java.io.ObjectInputStream.bufferData(ObjectInputStream.java:1750)
        at java.io.ObjectInputStream.readShort(ObjectInputStream.java:1935)
        at
java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:842)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
        at
org.apache.catalina.util.CustomObjectInputStream.<init>(CustomObjectInputStr
eam.java:103)
        at org.apache.catalina.session.JDBCStore.load(JDBCStore.java:518)
        at
org.apache.catalina.session.StoreBase.processExpires(StoreBase.java:295)
        at org.apache.catalina.session.StoreBase.run(StoreBase.java:350)
        at java.lang.Thread.run(Thread.java:484)

The relative portion of the server.xml file is...

<Context path="/library2" docBase="library2" debug="0" reloadable="true">
                                   <Manager 
className="org.apache.catalina.session.PersistentManager"
                                                          debug="0"
                                                          saveOnRestart="true"
                                                          maxActiveSessions="-1"
                                                          minIdleSwap="-1"
                                                          maxIdleSwap="-1"
                                                          maxIdleBackup="-1">
                                                          <Store 
className="org.apache.catalina.session.JDBCStore"
                                                          
driverName="org.gjt.mm.mysql.Driver"

connectionURL="jdbc:mysql://localhost/tomcatsessions?user=SessionTracking;pa
ssword=tracking"
                                                          sessionTable="sessions"
                                                          sessionIdCol="id"
                                                          sessionDataCol="data"
                                                          sessionValidCol="valid"
                                                          
sessionMaxInactiveCol="maxinactive"
                                                          
sessionLastAccessedCol="lastaccess"
                                                          checkInterval="60"
                                                          debug="99" />

                                        </Manager>


 </Context>



The servlet is straight from the book and it looks like this....

package chapter7;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionServlet extends HttpServlet {

  public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

      response.setContentType("text/html");

      PrintWriter out = response.getWriter();
      out.println("<html>");
      out.println("<body bgcolor=\"white\">");
      out.println("<head>");

      out.println("<title>Session Servlet</title>");
      out.println("</head>");
      out.println("<body>");

      // Get a reference to the HttpSession Object
      HttpSession session = request.getSession();

      // Print the current Session's ID
      out.println("Session ID:" + " " + session.getId());
      out.println("<br>");

      // Print the current Session's Creation Time
      out.println("Session Created:" + " " +
        new Date(session.getCreationTime()) + "<br>");

      // Print the current Session's Last Access Time
      out.println("Session Last Accessed" + " " +
        new Date(session.getLastAccessedTime()));

      // Get the name/value pair to be placed in the HttpSession
      String dataName = request.getParameter("name");
      String dataValue = request.getParameter("value");

      if ( dataName != null && dataValue != null ) {

        // If the Parameter Values are not null
        // then add the name/value pair to the HttpSession
        session.setAttribute(dataName, dataValue);
      }

      out.println("<P>");
      out.println("Sessions Attributes" + "<br>");

      // Get all of the Attribute Names from the HttpSession
      Enumeration names = session.getAttributeNames();

      while ( names.hasMoreElements() ) {

          String name = (String) names.nextElement();
          // Get the Attribute Value with the matching name
          String value = session.getAttribute(name).toString();
          // Print the name/value pair
          out.println(name + " = " + value + "<br>");
      }

      // Create a Form to Add name/value pairs to the HttpSession
      out.println("<P>GET based form:<br>");
      out.print("<form action=\"");
            out.print(response.encodeURL("chapter7.SessionServlet"));
      out.print("\" ");
      out.println("method=GET>");
      out.println("Session Attribute:");
      out.println("<input type=text size=20 name=name>");
      out.println("<br>");
      out.println("Session Value:");
      out.println("<input type=text size=20 name=value>");
      out.println("<br>");
      out.println("<input type=submit>");
      out.println("</form>");

      out.println("</body>");
      out.println("</html>");
  }
}


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to