• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

session attribute problem

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use session.getAttribute("tran")
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doh! I found it last night. Thanks. I shouldn't program late at night.

Joyce
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic