Hi
i am preparing for SCWCD and was going through
Servlet specification where i saw the following content about the request/response life cycle:
Each request object is valid only within the scope of a servlet’s service method, or within the scope of a filter’s doFilter method. Containers commonly recycle request objects in order to avoid the performance overhead of request object creation. The developer must be aware that maintaining references to request objects outside the scope described above is not recommended as it may have indeterminate results.
Let say i am sending request to Servlet1,so the container creates request and response object and pass the reference through service method of Servlet1.
Then this servlet uses the request dispatcher which forwards the request and reponse to the another servlet Servlet2 which do some complex computation.
Now the service method for Servlet1 is completed.So now as per the spec,the reference for request and response in the Servlet2 is not appropriate as it is outside the scope of service method of Servlet1?
Also i have seen many codes that uses forward to forward the request to different sources ,so does it mean that all the codes are vulnarable to the problem described inthe specification?
So can i assume that when we use forward from the request dispatcher,we are always prone to the problem mentioned inthe specification?