I have a web app which contains two servlets, one to render my JSP pages, and another to generate PDFs. I use session state between the JSP pages and want to pass a session object to the PDF servlet.
Here's an example of how I set the session values in the JSP:
MyObject o = (MyObject)session.getAttribute("my.object");
if (o == null)
{
o = new MyObject();
session.setAttribute("my.object", o);
}
I then post off to my new servlet for the PDF generation from a link in my JSP
<a href="../pdfgen?f=d&t=c" target="_blank">Generate a draft report for review</a>
I thought I could use the HTTPRequest object to return the session in my servlet as follows:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
HttpSession session = request.getSession(false);
MyObject o = (MyObject) session.getAttribute("my.object");
}
Using the above code I get a null session object from the request.
If I use request.getSession(true)
I get a session object, but of course it doesn't contain anything in the attribute my.object
.
How is this supposed to work? What are the rules about sharing session state between servlets.
Tomcat 6
TIA