Data AccessCore JavaApp FrameworksViewTestingBuildingDeploymentDev ToolsSecurityOpinions

Sunday, June 14, 2009

Struts2: Accessing Session Variables in JSP's

Struts 2 places named objects including the session onto the OGNL stack. Named objects can easily be retrieves using the s:property tag. For example:

<s:property value="%{#session.User.firstName}"/>


Struts 2 supports other named objects that can be accessed the same way. Suppose the attribute name attrName for all examples below.

Request parameter : #parameters['attrName ']
Request attribute : #request.attrName
Session attribute : #session.attrName
Application Attribute : #application.attrName

For more on OGNL basics, click here.

14 comments:

  1. Simple, yet very useful -- Thank You!

    ReplyDelete
  2. how to set a session object's variable using struts2?

    ReplyDelete
  3. Map session = ActionContext.getContext().getSession();

    session.put("user",userObject);

    ReplyDelete
    Replies
    1. thaaaaaaaaaaaaaaaaaaaanks

      Delete
  4. very useful thanks a lot

    ReplyDelete
  5. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Java Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai

    ReplyDelete
  6. Excellent post! Thank you for Sharing. We are the best erp software providers in chennai. For more details call +91 9677025199 or email us on info@bravetechnologies.in
    erp in chennai

    ReplyDelete
  7. Thank you for Sharing. I'm working in brave technologies private limited, We are the best erp software developers based in chennai. erp providers in chennai

    ReplyDelete
  8. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog.
    selenium training in chennai

    ReplyDelete
  9. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .
    office 2010 professional plus key deutsch

    ReplyDelete