Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp can't get object from servlet using "getAttribute"  RSS feed

 
Ian Yang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow,
I am using servlet 1.1 and jsp 1.0. In servlet,
I tried:
req.setAttribute(a, b);
res.sendRedirect("somejsp");
In somejsp:
Object o = request.getAttribute(a);
I didn't use "seeion.setAttribute" because I don't want session here. Now on the jsp side, the "request.getAttribute(a)" keeps returning null result. No compile error though. on jsp side, i also tried use
<jsp:useBean id="a" scope="request" class="..."/>
but same null result returns.
Should this work ? If not then maybe I have to use "forward(req, res)" to forward to jsp ?
Thanks,
ian
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point is that sendRedirect sends a message back to the browser and the browser creates a NEW request to a new URL - which could be to an entirely different system.
You are correct that forward keeps the same request object so you can store an object in it.
Bill
 
Ian Yang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much William !!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!