• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I preserve the resp object ?

 
Leena Diwan
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You William !
Leena
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic