Hello,
I've read on this list that Tomcat 3.2 supports
serializing sessions attributes. I wanted to try it,
but could not find more information on the subject
here. So I tried to do it according to the servlet 2.2
specification. As it is not working, I try to sum-up
here what I've done:
I have installed 2 Tomcat 3.2 on the same machine
(taking care that the 2nd Tomcat starts on port 8081),
and for each of them, I have built a very simple
"session" webapp :
- session/
- WEB-APP/
web.xml
- classes/
SessionServlet.class
The web.xml looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<distributable>
</distributable>
<servlet>
<servlet-name>session</servlet-name>
<servlet-class>SessionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>session</servlet-name>
<url-pattern>/session</url-pattern>
</servlet-mapping>
</web-app>
For the firt Tomcat, I compiled:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out = res.getOutputStream();
res.setContentType("text/plain");
out.println("SessionServlet 1 output");
ServletContext servletContext =
this.getServletContext();
servletContext.setAttribute("foo","abcdef..foo");
out.println("attribute foo, with value
"abcde...foo", added in ServletContext");
HttpSession httpSession = req.getSession();
httpSession.setAttribute("bar","abcde...bar");
out.println("attribute bar, with value
"abcde...bar", added in HttpSession");
out.close();
}
}
For the second Tomcat, I compiled:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out = res.getOutputStream();
res.setContentType("text/plain");
out.println("SessionServlet 2 Output");
ServletContext servletContext =
this.getServletContext();
String foo = (String)
servletContext.getAttribute("foo");
out.println("foo="+ foo +" (get from
ServletContext)");
HttpSession httpSession = req.getSession();
String bar = (String)
httpSession.getAttribute("bar");
out.println("bar="+ bar +" (get from
HttpSession)");
out.close();
}
}
Requesting respectively the first servlet, and the
second serlvet did not give the expected results:
http://127.0.0.1:8080/session/servlet/SessionServlet
SessionServlet 1 output
attribute foo, with value "abcde...foo", added in
ServletContext
attribute bar, with value "abcde...bar", added in
ServletContext
http://127.0.0.1:8081/session/servlet/SessionServlet
SessionServlet 2 Output
foo=null (get from ServletContext)
bar=null (get from HttpSession)
So did I made a mistake, did I forget something, or is
it simply not possible to do it ?
Thanks for any help !
Xavier Marjou
__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/