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.
Can this be done using pure Java at all? I heard there is this so called dependency injection but I am not sure how to make use of it in my case. Hope someone can also shed some light on this. Tks.
I am using Java EE7 and jdbc, 1.8 Java SE and Tomcat.