Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error while testing attributes

 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I tried the following,



I get null printed!
 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when I tried using a RequestDispatcher, I'm getting value printed??

Please help me ranchers!
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When you use sendRedirect, you are creating new request.The browser will show you the changing URL. It is not server-side forward. Though you are calling the jsp page in same container, the request attributes will not persist in case of sendRedirect.

Thanks
 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right. Got it. Thanks for the reply!
 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it's like a new request and response objects are created and to those new objects the attribute is not yet set, so we receive a null wehn we try to print it.

Got to understand it now.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Request parameters and attributes are not passed to the URL used in sendRedirect.

Thanks
 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say it's like making a new request all over again when using a sendRedirect, it means that we get a new request and response objects. So that is the clue as to what happens with the request attribute that I've set before doing the sendRedirect.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may set this idea in your mind anyway you are comfortable. The key idea is that sendRedirect fulfills that original contract (returns a response) with the client (browser) while returning a status that tells the browser to send another request to the address that you indicated in the redirect.
 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic