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.
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.
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
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
Joined: Jan 23, 2004
In conjuction with prevoius mail. I didn get what you wanted to say abt <jsp:forward> will like to know it . cheers!
subject: Maintaining State between different calls to jsp