Hi,

I am running into a problem when using "forward" method in my servlet to
forward the HttpRequest to a JSP page.

The servlet looks like this

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

    HttpSession session = request.getSession(true);
    System.out.println("ID " + session.getId());

    //do bunch of business logic here
    //do more things
    .
    .
    .


getServletConfig().getServletContext().getRequestDispatcher(theJSPPage).forw
ard(request,
response);

}

everything works except the forward part. Every time a JSP is displayed
as a result of forward method, the user is supposed to fill in stuff in
the page and get back to the same servlet after he submits on the page.

However, when the servlet takes over the second time, it has to create a
new session, and the SessionID is changed.
The expected behavior was that the session would have been maintained
though the control was passed from servlet->JSp->back to servlet.

If I comment the forward code statement and replace it by some code such
as

        PrintWriter out = response.getWriter();
        out.println("<html><head><title>Alternative
methods</title></head>");
        out.println("<body>");

and give a href to bring back the users to the same servlet, in that
case the session is retained.

Any ideas? Anyone? Anyone?

Thanks,
Seemantini Godbole

Reply via email to