Friday, 15 February 2013

java - ArrayList in Session object seems to lose contents -



java - ArrayList in Session object seems to lose contents -

i'm having problem retrieving , casting arraylist session. next error:

javax.servlet.servletexception: java.lang.indexoutofboundsexception: index: 1, size: 1

i stored arraylist in session:

list<userapplication> userlist = uadao.searchuser(eds); if (!userlist.isempty()) { request.getsession().setattribute("userlist", userlist); action_forward = editsuccess;

and casting session object arraylist, did following:

editstudentform edt = (editstudentform)form; if ((session.getattribute("userlist")) instanceof list){ list <userapplication> studtlist = (arraylist<userapplication>)session.getattribute("userlist"); } seek { uadao.edituser(edt,studtlist); action_forward = editsuccess; }

i'm getting error on here in dao class:

public void edituser(editstudentform edt,list studtlist) throws exception { preparedstatement pst = null; stringbuilder sb = new stringbuilder(); int stcode =integer.parseint(studtlist.get(1).tostring()); getting error here if (edt.gettitle() != null && !edt.gettitle().equals(studtlist.get(2).tostring())) { sb.append("title = '").append(edt.gettitle()).append("'"); } . .

in code:

editstudentform edt = (editstudentform)form; if ((session.getattribute("userlist")) instanceof list){ list <userapplication> studtlist = (arraylist<userapplication>)session.getattribute("userlist"); } seek { uadao.edituser(edt,studtlist); action_forward = editsuccess; }

you create new variable 'studtlist' never used. it's scope { } pair around 1 line.

there has variable same name, studtlist, in outer scope 'edituser()' phone call can work.

additional note

as other folks have answered, looks may doing .get(1) , expecting first element of array list. maybe. maybe not.

java

No comments:

Post a Comment