Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how do I set an entity to read in a list<string> from another entity?

User_DTTUYDec 8 2018 — edited Dec 12 2018

I have 2 entities - tutor and Subject.

At the controller, I have problem with the code where I need to set the tutor to get the list of subjects which are in String.

Here's the snippet of code in the servlet:

tutor m4 = new tutor();

String[] subj = request.getParameterValues("subject");

List<string>subjects = new ArrayList<string>(Arrays.asList(subj));

for(String subject : subjects){ //next() returned showed values
System.out.println(subject);//no explicit return value
// m4.setSubject(subject); //setSubject() returned null
//m4.setSubjlist(subjects);
m4.setSubjs((Subject) subjects);

I have tried various ways to set the subject at the class without avail.

The error message // shows that the tutor is not reading in the values

Here's how I did the setter at tutor class

public class tutor{
private String tutorName;
tutor subj;
public tutor setSubject(String subject) {
  return this.subj;
  }

My question is how do I write the setter in tutor Class in order for the code to work in the Servlet. I am using Java EE7 and jdbc, 1.8 Java SE and Tomcat.

Comments

Post Details

Added on Dec 8 2018
1 comment
208 views