Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

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

HI,

  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!

Thanks
0
mvkraju
Asked:
mvkraju
  • 2
  • 2
1 Solution
 
searlasCommented:
bean:write

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...)
http://jakarta.apache.org/struts/userGuide/struts-bean.html#write
0
 
mvkrajuAuthor Commented:
here you assigning key to the name attribute. How about property?
What are we assigning it for?
0
 
searlasCommented:
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)

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

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


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

Thanks for ur explanation.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now