Session persistence
javidjamae Jun 19, 2006 12:17 PMI'm trying to enable session persistence in jboss-4.0.4GA, but no SESSIONS.ser file is created. I followed the instructions in the global context.xml file in the root of the Tomcat service archive, which says to create a WEB-INF/context.xml file to enable session persistence for an individual app.
Unfortunately, no SESSIONS.ser file is created where I expected it, in the following directory:
jboss-4.0.4.GA\server\default\work\jboss.web\localhost\simple
I'm guessing one of the following:
1) Session persistence is broken in this release
2) There is an additional step that I'm missing, which is not mentioned in the global context.xml
3) My code is not using the session properly
4) The SESSIONS.ser file is being created somewhere else (but I think I've eliminated this as an option because I've restarted the server and my sessions are recreated from scratch)
Any suggestions would be greatly appreciated!!
Here is my code:
WEB-INF/context.xml
<Context cookies="true" crossContext="true"> <Manager pathname="SESSIONS.ser" /> <InstanceListener>org.jboss.web.tomcat.security.RunAsListener</InstanceListener> </Context>
WEB-INF/web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd"> <servlet> <servlet-name>Hello Servlet</servlet-name> <servlet-class>HelloWorldServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Hello Servlet</servlet-name> <url-pattern>/sayhello</url-pattern> </servlet-mapping> </web-app>
HelloWorldServlet
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @SuppressWarnings("serial") public class HelloWorldServlet extends HttpServlet { @Override public void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { PrintWriter out = response.getWriter(); HttpSession session = request.getSession( true ); Object o = session.getAttribute( "count" ); int count; if ( o == null ) { System.out.println("count was null"); count = 0; session.setAttribute( "count", count ); } else { count = (Integer) o; System.out.println("count was " + count); session.setAttribute( "count", ++count ); } out.println( "<html><body>I've said 'Hello World!' " + count + " times!</body></html>" ); out.close(); } }