This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session attribute problem

 
Joyce Derzaph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having trouble passing attributes back and forth between a servlet and a jsp.
I set the attribute in the servlet then forward the request and response to a jsp. The attribute shows up in the servlet but comes up null in the jsp.
Here is the code sections:

---servlet---
session.setAttribute("trans",t); // t was initialized earlier
RequestDispatcher rd = req.getRequestDispatcher("/mainTill.jsp");
rd.forward(req,res);

---jsp---
<% double total = 0;
Transaction t;
t = (Transaction)request.getAttribute("trans");
%>
<%= t.toString() %>
If anyone has any ideas I'd appreciate it. This is driving me nuts!

Joyce
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joyce Derzaph:

---
session.setAttribute("trans",t); // t was initialized earlier
---
t = (Transaction)request.getAttribute("trans");


You are setting 't' as a session attribute, but then you are trying to retrieve it as a request attribute.

either use setAttribute and getAttribute with the session object, or use both with the request object
 
jaya jaya
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use session.getAttribute("tran")
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64608
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jaya jaya",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Joyce Derzaph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! I found it last night. Thanks. I shouldn't program late at night.

Joyce
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic