Hey fellas, I have a bean called student with three private fields (name, grades and ID). Inside the servlet I get the three parameters through request.getParameters (from a HTML page) I put these parameters inside the student bean Student x = new Student (userName, userID, userGrade); how I have to this serialized bean into an arraylist so the user can keep entering data and the array list can keep growing. how would i go about this?
Maaz Ahmed wrote:If I am wrong, please correct me.
Well, here are some issues I found quite quickly:
You can't declare a List like that. You mean List<String>. You also don't need to create a new one if you're going to read its value from the session a bit later on.
That will only return true if the session contains an attribute that is not the String literal "". If it's an empty String that has been created in a different way, that still returns true. I don't really get what you're trying to do here. If you want to test for absence of the attribute, use null instead of an empty String.
That line will not compile, because HttpSession.getAttribute returns Object. You will need a cast to List<String>.