The moose likes Struts and the fly likes Have problems handlng sessions  need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Have problems handlng sessions  need help" Watch "Have problems handlng sessions  need help" New topic
Author

Have problems handlng sessions need help

Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
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

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Oct 11, 2006
Posts: 155
hiii...

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

Anil
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Have problems handlng sessions need help