• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Maintaining State between different calls to jsp

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Can anyone tell me what is the best way to maintain state between different client requests?
I used hidden form fields ,<jsp:forward > and kept setting the variable in the request attributes:-
request.setAttribute("foo",request.getParameter("foo"));
Problem with this was whenever a new form was submitted the request
attributes were lost and needed to be reassigned via hidden form fields.
Should i use session.setAttribute instead to pass around variables?
Or is cookies a better option? How should i decide?
Thanks,
Pallavi.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The recommended way to do this is to store you values in the session context. In most cases the session mechanism uses cookies "under the hood".
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Frank.
usually its best to avoid heavy requestobjects.
You can use session.setAttribute("foo") tp maintain the state. In case u have a number of parameters u better encapsulate them and then add it to the session context.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch "AmigoM"!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Additionally, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or chat room, it presents an extra challenge to those that are already struggling with English. I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not abbreviating these words.
Thanks!
bear
JSP Forum Bartender
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pallavi
This is one question that should definitely occur in every web developers mind.
Adding attribute in URLs is unsafe if method is not post.Also threre is limit to its size.
Hidden attributes again add up to the request object and as you realized request object is valid only for one 'request' (Sounding odd!)

Cookies if disabled by client browser wont work. Also user may manually delete them.
Best way is to put it in session object. But hey! wait dont make seesion object too heavy. First design your application such that minimum burdon is put on the session hourse which runs from here and there ;-)
SCJP,SCWCD
 
Dhondiba Joshi
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In conjuction with prevoius mail. I didn get what you wanted to say abt
<jsp:forward> will like to know it .
cheers!
 
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic