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

Setting a session attribute in a servlet

Robert Stone
Greenhorn

Joined: Jan 06, 2011
Posts: 25
Hi I am having trouble setting a session attribute in a servlet and retreiving it in the jsp the servlet forwards to.

Below is the code from the servlet and the jsp. For some reason even thought I set the session attribute in the servlet when it forwards to the jsp the attribute is null.

//Servlet code here


//JSP code here


Any help will be greatly appreciated.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Are you sure that the variable isn't null to being with?

P.S. And why the session? Placing the scoped variable on the request is sufficient for a forward operation.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Robert Stone
Greenhorn

Joined: Jan 06, 2011
Posts: 25

Are you sure that the variable isn't null to being with?

Yes I am sure it isn't null I ran it under eclipse and in the debugger I can see the object is populated before I put it into the attribute.

P.S. And why the session? Placing the scoped variable on the request is sufficient for a forward operation.

because it is a object that contains data that I want to access on a couple of pages.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
I wonder if you are even seeing the same session in the jsp - you seem to be forwarding to a different web app address so you will get a different session.

Bill
 
Don't get me started about those stupid light bulbs.
 
subject: Setting a session attribute in a servlet