This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have a servlet and in order to maintain thread-safety, I've removed all the instance variables from it. I have multiple methods in this servlet. The request parameters and their values must be shared among these methods. This servlet wouldn't forward the response to any jsp/servlet. Instead, it generates a xml file which is directly written to the response's output stream. Right now, I am using request attributes to share the information between different methods of the same servlet. Is this a good approach? Are there any other alternative ways that I'm missing? I read, request attributes are used in combination with RequestDispatcher. However, I don't need any RequestDispatcher. Does my approach make sense? Could you please guide me?
As far as I remember (somebody fix me if i'm wrong!), the container creates new Request and Response objects before it gets to the Servlet's service() method (just before assigning new thread to this request).
After the response is sent to the client, the thread finishes and Response and Request objects are eligible for GC.