Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

session.Attribute returns null  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my code:
<% session.setAttribute("id",request.getParameter("idField"));
session.setAttribute("Name",User.getRepresentative());
%>
I get the idField from a html form and the name from a bean then I store them in the session. Simple, right.
Then in the next jsp page, I try to read the Name and the id field but it displays null. This is how I try to read them:
<%= session.getAttribute("Name") %> <br />
<%= session.getAttribute("id") %>
I check the session Id, and they were the same on the two jsp pages. What am i doing wrong. I can't figure it out. Could it be that my tomcat is not configured right? Thanks in advance for your help.
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad,
It may sound silly but have you checked that your request.getParameter("idFeild") is pulling the value from the form and not just giving you a null? It might be worth checking. Just before setting it to session stick in a line like:
System.out.println(request.getParameter("idField"));
HTH
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, one thing to check is that you are writing values to the session and not just 'null', the other is to make sure the session ID is the same both times. There are times when you accidentally lose the session, and you'd have to solve this problem first.
Dave
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!