This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hidden field retrieval

 
AbhisheK Aggarwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am setting a variable in the session using in the java script but am not able to retrieve it...

at the web page :


the alert works just fine but when i try to retrieve it at the servlet


gets a null value

i even tried

thanks
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Nothing will be in the session unless it is explicitly put it there. So unless there's a session.put("send", ...) somewhere, it won't be in the session.

As regards the JavaScript code, is the form where you're setting the value submitted after it's set? Have you verified that the value gets transmitted to the server? If not, the Firefox extension LiveHttpHeaders is a great tool to observe what gets sent to the server, and what the server sends back (in other words, it logs HTTP requests and responses).
 
AbhisheK Aggarwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was submitting the form before setting the variable...thanks for your prompt reply
 
Mike Anna
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


HttpSession session= req.getSession(false);String saveString = session.getattribute("send");


These lines, my friend, I hope you understand, what they are doing.
Why dont you change your first line from this

to this


and let us know what happened. I am assuming you have a hidden variable named "send"
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These lines, my friend, I hope you understand, what they are doing.
Why dont you change your first line from this

That can't possibly be the problem, because in that case a NullPointerException would have been thrown during when calling session.getattribute("send"). But that's moot, since the problem is solved already.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic