• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Struts: Request/Session Attribute

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Jolly Ranchers:
Here's my problem:
I have a page with a list of items. You can select an item for various operations (view, edit delete). When the user selects an item and then presses a button (invoking the desired operation) the Action object stores an object corresponding to the selected item as a request attribute. On a delete I display a confirmation jsp. This jsp retrieves the request attribute and displays identifying info for the item. If the user confirms the deletion I want the next Action to perform the deletion. But since this is a new request the request attribute is no longer available - so how can I inform the Action which item to delete. I can think of 2 ways to accomplish this:
1) Use a session attribute instead of a request attribute. This doesn't seem right to me because I only want the job selection to exist for the current operaton.
2) Use a hidden field to store the item id. This seems hoky to me.
I would appreciate any feedback on this - is my understanding of the mechanics faulty? Any opinions on best practices for this kind of thing?
Thanks!
Mars
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classic web development problem: handling state. Your item id is the state you want to maintain between calls to your delete and confirm pages.
The standard ways of dealing with this are firstly and secondly as you mentioned in session and then in a hidden field, but thirdly in a cookie, and fourthly in a URL as a querystring parameter.
The first method keeps the info on your server, which can be unsuitable if there is a heavy load because your server will then have to have the memory to deal with it, or it will crash. (For your example though the small amount of memory needed to store an item id is virtually insignificant).
The other methods send the info out to the browser and depend on the browser sending it back again. In your case, since you are already sending info about the article to the browser for confirmation, why not send the id as well?
 
Acetylsalicylic acid is aspirin. This could be handy too:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic