File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session attribute problem

 
Joyce Derzaph
Greenhorn
Posts: 14
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use session.getAttribute("tran")
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic