tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Boyle, William (CAP, TIP)" <William.Bo...@gecapital.com>
Subject RequestDispatcher/Session problems
Date Fri, 08 Jun 2001 15:08:16 GMT
I am having problems with the following code (this is just a simplified example):

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class TestSession extends HttpServlet {
  public void doGet( HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
	RequestDispatcher rd = req.getRequestDispatcher("/servlet/TestSession2");
	rd.include(req, res);
	HttpSession session = req.getSession(true);
	session.setAttribute("msg", "The session is functioning properly.");
  }
  public void doPost( HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
	RequestDispatcher rd = req.getRequestDispatcher("/servlet/TestSession2");
	rd.include(req, res);
  }
}

public class TestSession2 extends HttpServlet {
  public void doGet( HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
	PrintWriter out = res.getWriter();
	out.println("<HTML><HEAD><TITLE>TestSession</TITLE></HEAD>");
	out.println("<BODY><FORM method=POST name='testform' action='/QuickQuote/servlet/TestSession'><INPUT
type='submit' name='Submit' value='Suck it up'>");
	out.println("</FORM></BODY></HTML>");
  }
  public void doPost( HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
	HttpSession session = req.getSession(false);
	PrintWriter out = res.getWriter();
	if(session == null)
		out.println("no session");
	else
		out.println(session.getAttribute("msg"));
  }
}

When I run this (Tomcat 3.2.2 using JSDK 2.2), it seems to create a session successfully,
however after the post back, it will be unable to find an existing session.  If I move the
two lines creating the session and adding msg to it into the doGet method of the TestSession2
servlet it works fine tho.  The basic problem I have found is concerning creating a
session after a RequestDispatcher.include call has returned.  Would this be a Tomcat issue
or a JSDK issue?

Mime
View raw message