i am new to servlet and jsp..I retrieve values from database and set it in a arraylist of bean in servlet.That arraylist of bean is later displayed in jsp page...But after at second run of servlet duplicate values get printed in jsp..Guys help me....
Joined: Mar 22, 2005
You seem to assume that on each request a new instance of the servlet will be created, and hence you'll have a fresh and empty instance of "allData" to work with. That's not how servlets work - there will only ever be a single instance of the servlet class, and it is used to serve all requests.
But you can't just clear out that List before you use it, either, because instance variables are shared between simultaneous requests, so you might be interfering with other requests.
So it's best to avoid instance variables until you have a much better understanding about how concurrency works in web apps. Luckily, that's very easy to achieve in this case.
(I've also added code tags to your post - see how much easier it is to read that way? Please UseCodeTags in the future.)