Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 06-16-2005, 04:31 AM   #1 (permalink)
edwardmraj
Registered User
 
Join Date: Jun 2005
Posts: 3
edwardmraj is on a distinguished road
How to Nullifying the Arraylist Object?..

hi all

How to Nullifying the ArrayList Object in JSP .

For Eg.

I declared an ArrayList as below in the Code. Beacause i am going to add an object in to Arraylist using while loop.

-------JSP File Code ---------------
<! ArrayList alTest = new ArrayList(); >

while(condition)
{

<jsp:usebean id="test" class="com.beanclass" scope="request">
<jsp:setproperty name="test" property="strCCNO1" param="textCCNo1"/>
<jsp:setproperty name="test" property="strCCNO2" param="textCCNo2"/>
<jsp:setproperty name="test" property="strCCNO3" param="textCCNo3"/>
</jsp:usebean>

<%
alTest.add(test); //Object of the Bean
%>

<%
request.setAttribute("lis","alTest");
}
%>

<jsp:forward page="servlet" />

---------------------End Code----------------

Thro refreshing the page i'm entering the value in the textboxs and setting the values using methods in <jsp:usebean> . Then i am adding the usebean object to arraylist.

it working fine . no problem.....

Here the Arraylist declared as global<%! Arraylist al= new ArrayList()%>, so what's happening , if more than one user try to access the page and do the same thing, that's also added in the same arraylist object.


Also when i try to declare that AL as in local ie <% Arraylist al= new ArrayList()%> it's every time refresh and create new object. so i con't store that bean objects in loop.



So How to solve this problem???? Is possible to have the arraylist as global and acheive this task? or else

If any one give the solution for this really it will help me lot!!

Thanks in Advance......

EDward
edwardmraj is offline   Reply With Quote
Old 06-16-2005, 02:50 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
You could declare it locally, and then store it in session scope. That will let it survive a reload, but make it individual to each session. You'll just have to check and see if it exists before creating a new one.

*edit* Ah, this is linked to your last post, isn't it? So that rules out using the session object. Well, you're using beans (so I'm not really sure why you can't use the session object), so why don't you shove it in there to keep it's state?

You're going to need to use some sort of session-based mechanism if you want it to survive a reload.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get an ArrayList Object in servlet from JSP? edwardmraj Java 2 06-10-2005 08:15 AM
Is a Static Reference to an Object Garbage Collected? dancer Java 1 03-01-2005 10:50 AM


All times are GMT -8. The time now is 01:29 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting