how to display key, value which is stored in session object in a JSP using struts


  I am passing key, value pair with session object.
I wanted to display this value in my JSP using struts.
Which tag of struts i suppose to use.

I appreciate ur help!

Who is Participating?
searlasConnect With a Mentor Commented:

Let's suppose your key value is an instance of Map.Entry...

Presumably, somewhere you have:
session.setAttribute("mypair", mapEntry);

Then, in your JSP
<bean:write name="mypair" property="value" scope="session"/>

(scope="session" is optional...)
mvkrajuAuthor Commented:
here you assigning key to the name attribute. How about property?
What are we assigning it for?
You have your name/values in an object,  I'm using the class Map.Entry as an example, this has two relevant methods, getKey() which returns the key, and getValue() returning the value.

name - the name the name-value-pair object is stored as under the session
property - the method to call on the name-value-pair object to retrieve the value (minus 'get', and always start lower case)

<bean:write name="mypair" property="value" scope="session"/>

Is effectively the same as saying:
out.write( ((Map.Entry) session.getAttribute("mypair")).getValue() );

mvkrajuAuthor Commented:
It's working fine.
if worked with out property attribute also
<bean:write name="mypair" scope="session"/>

Thanks for ur explanation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.