Hi Dillard,

Thank you very much for your advice.
The problem is solved already.
This week I will be refactoring project using Servlets and for sure I 
will have further questions :)

BR
Rafal

Dnia 21-12-2009 o godz. 16:29 Dillard Derek napisał(a):
> Hi Rafal,
> You may need to provide more information on your problem, but this is
> how I see it...
> 
> From what you've provided, it looks like your form takes only one
> person's name (first, surname), etc and then the form is submitted. If
> that is the case, then I'm assumin you expect each html form submission
> to call a jsp which will set values for a Person object, and then add
> that Person object to an List.
> 
> The problem with your code is that your List changes each time the form
> is submitted. What I mean is, each time result.jsp is generated, it
> generates a new List object. This is because when you create a variable
> in a scriptlet (anything beteen <% and %>), the variable is local to the
> _jspService method that is run in a separate thread for each request. So
> this variable is re-initialized for every request. This is why you only
> get the last record in your List. It is only holding one Person object
> at a time.
> 
> If you want your List retain the Objects you've previously created, you
> could declare the List object like this: <%! List list = new ArrayList()
> %> (note the exclamation in the declaration) and then use it in your
> scriptlet. Keep in mind that this is not thread safe, but should work
> for your purposes.
> 
> HTH.
> -d.
> 
> -----Original Message-----
> From: java-ee-j2ee-programming-with-passion@googlegroups.com
> [mailto:java-ee-j2ee-programming-with-pass...@googlegroups.com] On
> Behalf Of Rafal Laczek
> Sent: Sunday, December 20, 2009 9:22 AM
> To: Java EE (J2EE) Programming with Passion!
> Subject: [java ee programming] JSP/Arraylist
> 
> Hi,
> My form.html is following:
> <form action="result.jsp" method="get">
>     <p>First name <input type="text" name="firstName" /></p>
>     <p>Surname    <input type="text" name="surname" /></p>
>     Male<input type="radio" name="sex" value="male" />
>     Female<input type="radio" name="sex" value="female" /><br>
>     Preferable country to live <select name="countryType">
>       <option value="poland">Poland</option>
>       <option value="norway" selected>Norway</option>
>       <option value="hungary">Hungary</option>
>       <option value="vietnam">Vietnam</option>
>       <option value="uk">UK</option>
>       <option value="france">France</option>
>     </select>
>     <p><input type="submit" /></p>
>   </form>
> 
> And code in result.jsp is:
>    Person person1 = new Person();
> person1.setFirstName(request.getParameter("firstName"));
> person1.setSurname(request.getParameter("surname"));
> person1.setSex(request.getParameter("sex"));
> person1.setCountryType(request.getParameter("countryType"));
> 
> List list = new ArrayList();
> 
> list.add(person1);
> 
> //out.println("Arraylist has " +list.size()+ " objects");
> 
> for (Iterator it = list.iterator(); it.hasNext();){
> Person person =(Person)it.next();
> out.println(person.getFirstName());
> out.println(person.getSurname());
> out.println(person.getSex());
> out.println(person.countryType());
>  }
> Unfor
> tunately it seems that only last record inserted in form.html is added
> to the list as the result.jsp displays only this last record.
> Can you help me please.
> 
> Best regards,
> Rafal Laczek
> 
> ----------------------------------------------------
> Pozbieraj treści ze swoich ulubionych stron w jednym miejscu!
> I napisz koniecznie, czy ci się spodobało!
> Internet od nowa:
> http://klik.wp.pl/?adr=http%3A%2F%2Fpozbierane.pl&sid=932
> 
> 
> --
> You received this message because you are subscribed to the Google
> Groups "Java EE (J2EE) Programming with Passion!" group.
> To post to this group, send email to
> java-ee-j2ee-programming-with-passion@googlegroups.com
> To unsubscribe from this group, send email to
> java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

----------------------------------------------------
Zainwestuj pieniądze w nieruchomości w górach.
Sprawdź najnowsze oferty w Zakopanem i okolicach - Kliknij:
http://klik.wp.pl/?adr=www.bachledanieruchomosci.pl&sid=934


-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Reply via email to