java - JSP Iterate over a user-defined class that inherits -
I have two unit classes that represent two tables in my database, two table users and students are student class (user ID, student ID, class ID) is obtained from user category (id, first name, last name, email). When I ask the students for the database, a list has been returned to me, then I want to use it to recycle the list and display FirstName, last name, email and class for each student. However, it only shows class ID. I believe this is because the object belongs to a student, which includes only three fields (user id, student id, class id) and does not include name and email. However, because the student class increases the user class , I think that still should be able to get other fields.
Here are my classes
User
Public Class User {Private id ID; Private string first name; Personal string last name; Private string email; Public user () {} public string getFullName () {return firstName + "" + lastName; } Public int getID () {return ID; } Public Zero setID (int id) {this.id = id; } Public string getFirstName () {return firstName; } Public Zero SetFirst-name (string first name) {this.firstName = firstName; } Public string getLastName () {lastName; } Public Zero setLlastName (string last name) {this.lastName = lastName; } Public string getEmail () {return email; } Public Zero Set Email (String Email) {this.email = email; }}
Student
Provides a public class student to the user {Private Ent user ID; Private Ent Scholarship Private Private Class ID Public Invent UserID () {User ID Return; } Public Zero Set userid (int user id) {this.userID = userID; } Public Ent Student ID () {return studentID; } Public Zero Setstrudent id (Int studentID) {this.studentID = studentID; } Public int getClassID () {return classID; } Public Zero setClassID (int classID) {this.classID = classID; }}
JSP
& lt; C: Each item = "$ {students}" var = "student" & gt; & Lt; TR & gt; & Lt; Td> $ {Student.firstName} $ {student.lastName} & lt; / Td> & Lt; TD & gt; $ {Student.email} & lt; / TD & gt; & Lt; TD & gt; $ {Student.classID} & lt; / TD & gt; & Lt; / TR & gt; & Lt; / C: foreach & gt;
In my Controller class
list & lt; Students & gt; Students = get student (); Output.addObject ("students", students);
How can I display it, user.firstName, user.lastName, user.email, student.classID
The JSP code looks OK.
If the value is not available in the student object and it should be due to the ordering, then the problem is in the code that after the query the student populates the objects. You can validate how the student object is created and why the field related to the user object is not set.
Comments
Post a Comment