aspose file tools*
The moose likes JSP and the fly likes session attribute problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "session attribute problem" Watch "session attribute problem" New topic
Author

session attribute problem

Joyce Derzaph
Greenhorn

Joined: Mar 18, 2004
Posts: 14
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

Joined: Feb 02, 2002
Posts: 1211

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


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
jaya jaya
Greenhorn

Joined: May 17, 2003
Posts: 8
Use session.getAttribute("tran")
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61199
    
  66

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joyce Derzaph
Greenhorn

Joined: Mar 18, 2004
Posts: 14
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
 
subject: session attribute problem