spring - Getting java.lang.NumberFormatException when displaying data in JSP page -
i using hibernate , spring mvc. trying fetch information 2 tables , display in jsp page . here tables:
table name : student
student_id studentname 1. jason stathum
table name : studentdetails
studentdetailsid fathername mothername student_id 1 mr.x mrs. y 1
in jsp page trying display data this:
sl# student father mother 1 jason stathum mr.x mrs.y
when run application see data following error message:
http status 500 - exception occurred processing jsp page /web-inf/views/studentlist.jsp @ line 29 root cause java.lang.numberformatexception: input string: "fathername" java.lang.numberformatexception.forinputstring(unknown source) java.lang.integer.parseint(unknown source) java.lang.integer.parseint(unknown source).... , many other lines...
i have included codes below, please tell me doing wrong?
thank much
entity: student
@entity @table(name = "student") public class student { @id @generatedvalue(strategy = generationtype.auto) @column(name="student_id", nullable= false) private integer studentid; private string studentname; @onetomany(cascade = cascadetype.all) @joincolumn(name="student_id", referencedcolumnname="student_id") private list<studentdetails> studentdetails = new arraylist<studentdetails>(); // getters , setters public integer getstudentid() { return studentid; } public void setstudentid(integer studentid) { this.studentid = studentid; } public string getstudentname() { return studentname; } public void setstudentname(string studentname) { this.studentname = studentname; } public list<studentdetails> getstudentdetails() { return studentdetails; } public void setstudentdetails(list<studentdetails> studentdetails) { this.studentdetails = studentdetails; }
entity : studentdetails
@entity @table(name = "studentdetails") public class studentdetails { @id @generatedvalue(strategy = generationtype.auto) private integer studentdetailsid; private string fathername; private string mothername; // getters , setters public integer getstudentdetailsid() { return studentdetailsid; } public void setstudentdetailsid(integer studentdetailsid) { this.studentdetailsid = studentdetailsid; } public string getfathername() { return fathername; } public void setfathername(string fathername) { fathername = fathername; } public string getmothername() { return mothername; } public void setmothername(string mothername) { mothername = mothername; }
controller
@requestmapping(value="studentlist", method = requestmethod.get) public string getrecords(model map) { list<student> student = studentservice.getall(); map.addattribute("student", student); return "studentlist"; }
studentdaoimpl
@override @suppresswarnings("unchecked") public list<student> getall() { return getsessionfactory().opensession().createquery("from student").list(); }
jsp page: studentlist
<c:if test="${!empty student}"> <table class="studenttable"> <tr> <th>sl#</th> <th>name</th> <th>father</th> <th>mother</th> </tr> <c:set var="count" value="0" scope="page" /> <c:foreach items="${student}" var="row"> <c:set var="count" value="${count + 1}" scope="page"/> <tr> <td>${count}</td> <td>${row.studentname}</td> <td>${row.studentdetails.fathername}</td> <--- line 29 <td>${row.studentdetails.mothername}</td> </tr> </c:foreach> </table> </c:if>
the problem trying reference property of list
object.
${row.studentdetails}
= list<studentdetails>
jstl trying convert fathername
number can index in list<studentdetails>
.
to fix ${row.studentdetails[0].fathername}
or put method in student
called getdefaultstudentdata()
return first or "preffered" student details object reference ${row.defaultstudentdata.fathername}
. or of course change output deal multiple student details per student ☺
Comments
Post a Comment