• 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

Have problems handlng sessions need help

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guyzz

thanks for the solution i passed a parameter in the link and retrieved the value in the corresponding action class....


i have another problem now its that i have to generate some drop downs dynamically ...ie to add values from the database itself..
What i did was that i created an action class for the home page and pointed all my links to the home page.. here i got the values from the database and populated an arraylist with these values..
my problem is i can run the application the first time properly but if i try to access the same page twice the drop downs will have the same values added twice and would keep on increasing....

i know its the problem with my session variable...how do i control it

List myList = (List)request.getSession().getAttribute("myList");if (myList == null) { // create the list here} else { // do nothing}


I used the above code but it didnt work.... the session variable is saving the previous values ...
how do i remove the previous values without appending the new with the old valuesss...


Anil
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us your code. Include the bits of code from your Action class that control the collections that you say are growing with each invocation.
 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hii,


this is the code of my action class
rs=st.executeQuery("select assetType from Asset");
while(rs.next())
{
assetTypes.add(rs.getString(1));
}
session.setAttribute("assetTypes",assetTypes);

inside the jsp page i get these values and add it to the drop down...


every time that jsp page is called it passes through the action class and the session adds values to the already existing ones...


how do i reset it .....(session).
anil
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you didn't understand my meaning before, but if you do it properly, the "lazy initialization" technique I showed you in a earlier post will solve this problem. Example:


The block of code inside the if condition can only run once. If the same action is called again, the if condition will be false and the database access code will not execute.
 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hiii...

Thanks pal it worked you saved my day....

Anil
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic