Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4041040
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:49:48+00:00 2026-05-20T12:49:48+00:00

I need to persist an object over multiple requests in my Struts 2 application.

  • 0

I need to persist an object over multiple requests in my Struts 2 application. Is it better to put the object into Session or maintain it on Struts 2’s Value Stack?

So, is there a real difference (performance or otherwise) between persisting an object in the session vs. maintaining the object on the Value Stack?

1) Session

mutableSDO = getSession().get(SESSION_OBJ_IDENTIFIER);

// manipulate object

getSession().put(SESSION_OBJ_IDENTIFIER, mutableSDO);

2) Maintain in value stack

<s:property name="mutableDTO"/>
...

// mutableDTO instance variable set by Struts 2, value from client submit action

// mainpulate mutableDTO

this.mutableDTO = changedDTO;

// jsp uses changed DTO
...
<s:property name="mutableDTO"/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:49:48+00:00Added an answer on May 20, 2026 at 12:49 pm

    In S2 application, session, request, and parameters are all part the value stack.

    Request scope is exposed by default but you need # to access the other scopes.

    If you prefix an attribute with # it will access the aforementioned scopes in the order they appear until the attribute is found. It multiple attributes of the same name appear in the stack of scopes you will need to explicitly look up the required scope with #scope_name.attr.

    Between your option 1 and option 2. Only option 1 will persist over multiple requests (actually all requests that maintain a session). The second does not maintain the value over any time but one request, bubbling it forward from one request to the next. The first will let a user go to any page in your application randomly and be able to access the sored value, the second depends on forwarding to the correct pages.

    Say you have populated a table of employees and want to go to a details page of the employee, you should only have the employee id in request scope. Even if you need to use emp_id multiple times you should not have it in session scope. So if you are chaining forward and have the data in hand this is the right way to go.

    If you have some user preferences say, backgroud color. Then this would be a fine thing to put into a session value because a group or all pages will use it.

    The main consideration is if the user opens multiple windows and hits the refresh button, will the site behave as expected? Consider a user opening multiple employee details windows, if the value were loaded as a session value instead of passed as get parameters (which are in the request scope), a user hitting refresh to see the latest employee data on each window would only get the last employee loaded on the session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to persist just one object in session scope of my JSF application.
I have a set of configuration items I need to persist to a human
We have a need to create SQLAlchemy classes to access multiple external data sources
In my ASP.NET web-application I use NHibernate to persist my User-Instances, where each of
I need to persist the sort, filter and pagination state of a jqGrid that
I need to develop a file indexing application in python and wanted to know
I need to persist several classes with A LOT of static fields (which are
I have a multi step form which uses one model object and I need
Need a function that takes a character as a parameter and returns true if
Need a way to allow sorting except for last item with in a list.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.