File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Can I preserve the resp object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can I preserve the resp object ?" Watch "Can I preserve the resp object ?" New topic
Author

Can I preserve the resp object ?

Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
Hello Friends,
Can I preserve the response object even after forwarding the request using the requestDispatcher ?
Like Servlet1 forwards to Servlet2, and the response obeject is not flushed.
Thanks,
Leena


[SCJP2, SCWCD1.3, SCBCD]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
You should not try to hang on to either the request or the response object beyond the end of the response. After forwarding a request your servlet code should immediately return.
Bill
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351

1. Can we do it though ?
2. Any precautions I can take not to make it all go worse ?
My requirement is a bit changed.
Servlet1 -> Servlet2 -> Servlet1 and I want to preserve the response of Servlet2 in Servlet1.
Leena
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
Since the request and response are objects generated by the servlet engine, you should not try to hang on to them past the end of the request. Otherwise you mess up the servlet engine's management of memory.
With your new requirements, you should be doing an include, not a forward - there is a big difference in handling, take a look at the javadocs for RequestDispatcher.
Bill
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
Thank You William !
Leena
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I preserve the resp object ?