• Post Reply Bookmark Topic Watch Topic
  • New Topic

session.Attribute returns null

 
Ahmad Noori
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.
 
Faisal Khan
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
 
David O'Meara
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!