java - How to access properties of a object stored in list which itself is variable of a class using jsp el -
i trying access variable of object present in list. list variable member of object. m trying display variable using jsp expression language getting error.
my jsp page follows
<h5> ${group1.group_name}</h5> <div> <ul class="list-group"> <li class="list-group-item title"> <strong style="display:inline;"> about: <h5 style="display: inline;"> ${group1.group_description}</h5></strong> </li> <c:foreach var="member" items="${members_list}"> <li class="list-group-item title"> <img src="${pagecontext.request.contextpath}/css/images/user.png" class="img img-circle" style="display: inline" /> <strong style="display:inline;"> ${member.groupmemberslist.member_name} <h5 style="display: inline;">(${member.groupmemberslist.member_usertype})</h5></strong> </li> </c:foreach> </ul> </div> </c:foreach> my servlet passess values attributes jsp above
//current user's user-name string currentuser = request.getparameter("username"); string group_name=null; string getgroupinfo = "select * groups creator_username=?"; //get groups creator's user-name currentuser try { list<groupobject> groups = new arraylist<groupobject>(); list<group> singlegroup = new arraylist<group>(); ps3 = currentcon.preparestatement(getgroupinfo); ps3.setstring(1,currentuser); rs3 = ps3.executequery(); //set values group object while(rs3.next()) { groupobject groupobj = new groupobject(); group group = new group(); groupobj.setgroup_id(rs3.getstring("group_id")); groupobj.setgroup_name(rs3.getstring("group_name")); groupobj.setgroup_description(rs3.getstring("group_description")); group.setgroup_id(rs3.getstring("group_id")); group.setgroup_name(rs3.getstring("group_name")); group.setgroup_description(rs3.getstring("group_description")); singlegroup.add(group); string query = "select * group_members group_id=?"; ps = currentcon.preparestatement(query); ps.setstring(1, groupobj.getgroup_id()); rs = ps.executequery(); list<groupdetails> memberslist = new arraylist<groupdetails>(); while(rs.next()) { groupdetails groupinfo = new groupdetails(); groupinfo.setis_admin(rs.getstring("is_admin")); groupinfo.setadded_on(rs.getstring("added_on")); groupinfo.setcreator_username(rs.getstring("creator_username")); groupinfo.setgroup_name(rs.getstring("group_name")); groupinfo.setgroup_id(rs.getstring("group_id")); groupinfo.setuser_name(rs.getstring("user_name")); groupinfo.setmember_id(rs.getstring("member_id")); string memberfullname = "select firstname,lastname,user_type users username ='" + groupinfo.getuser_name() + "'"; ps2 = currentcon.preparestatement(memberfullname); rs2 = ps2.executequery(); if(rs2.next()) { string member_fullname = rs2.getstring("firstname") + " " + rs2.getstring("lastname"); groupinfo.setmember_name(member_fullname); groupinfo.setmember_usertype(rs2.getstring("user_type")); } group_name = groupinfo.getgroup_name(); memberslist.add(groupinfo); } groupobj.setgroupmemberslist(memberslist); groups.add(groupobj); } //request group name request.setattribute("group_name",group_name); request.setattribute("individual_group", singlegroup); request.setattribute("members_list", groups); request.setattribute("currentuser", currentuser); requestdispatcher rd = request.getrequestdispatcher("/viewallexistinggroups"); rd.forward(request, response); } catch (sqlexception e) { e.printstacktrace(); } my groupdetails class
package pojo.group; public class groupdetails { private string member_id; private string user_name; private string creator_username; private string group_id; private string group_name; private string added_on; private string is_admin; private string member_name; private string member_usertype; public string getmember_id() { return member_id; } public void setmember_id(string member_id) { this.member_id = member_id; } public string getuser_name() { return user_name; } public void setuser_name(string user_name) { this.user_name = user_name; } public string getcreator_username() { return creator_username; } public void setcreator_username(string creator_username) { this.creator_username = creator_username; } public string getgroup_id() { return group_id; } public void setgroup_id(string group_id) { this.group_id = group_id; } public string getgroup_name() { return group_name; } public void setgroup_name(string group_name) { this.group_name = group_name; } public string getadded_on() { return added_on; } public void setadded_on(string added_on) { this.added_on = added_on; } public string getis_admin() { return is_admin; } public void setis_admin(string is_admin) { this.is_admin = is_admin; } public string getmember_name() { return member_name; } public void setmember_name(string member_fullname) { this.member_name = member_fullname; } public string getmember_usertype() { return member_usertype; } public void setmember_usertype(string member_usertype) { this.member_usertype = member_usertype; } } any welcomed. how can acess member_name property groupdetails object stored in list groupmemberslist variable of groupobjects. jsp el plz
you missing member_name. it's coming null , causing issues. wanted member_id. code provided doesn't have mentioning of member_name there. check , ensure application going inside if(rs.next()){...} control flow block has assignment member_name request parameter.
update
after comments regarding access of java objects in jsp, following example should work you
<p> member name : <jsp:usebean id="your_object_name" class="package.with.class"> <jsp:getproperty name="your_object_name" property="member_name"> </p> replace text inside quotation mark have class , package names correctly.
Comments
Post a Comment