• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Have problems handlng sessions need help

 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • 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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
hiii...

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

Anil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic