tags:

views:

241

answers:

3

I want to check if a certain key/value pair has been set.

How do I check if a an entry with key named "keyName" exists. Sample code or a pointer to an example would be appreciated.

+1  A: 

Heres a simple introductory tutorial to JSP Sessions

In essence you should just need to check that session.getAttribute("keyName") is not null.

James
How do you recognize whether you set keyName to null, or it's not set at all?
Piskvor
I would imagine that it would no doubt contain some form of data if it was set.
James
+1  A: 

You can set/get attributes (key/value) in a HttpSession object. An example: http://www.exampledepot.com/egs/javax.servlet/State.html

nkr1pt
+2  A: 

If you want to differ between "not set" and null, step through session.getAttributeNames() and search your key name.

Christian Strempfer