**professors_courses** is the bridge table between professors and courses.
In *CourseAssignments.java* I search which courses belong to professor x, after user enters a professor "name".
**Course.java**
Expand|Select|Wrap|Line Numbers
- public class Course {
- private int course_id;
- private String title;
- public Course(int id, String title){
- super();
- this.course_id = id;
- this.title = title;
- }
- public int getCourse_id(){
- return course_id;
- }
- public String getTitle(){
- return title;
- }
Expand|Select|Wrap|Line Numbers
- Same with **Professor.java**:
- public class Professor {
- private int prof_id;
- private String name;
Expand|Select|Wrap|Line Numbers
- Same with **PC.java**:
- public class PC {
- private int prof_id;
- private int course_id;
**
Expand|Select|Wrap|Line Numbers
- ArrayList<PC> results** contains prof_id <-> course_id
Expand|Select|Wrap|Line Numbers
- ArrayList<Course> courses** contains course_id <-> title (identical with the table "courses")
In "professors" table we have prof_id: 5, name: John;
In "professors_courses" we have prof_id: 5, course_id: 1
prof_id: 5, course_id: 9
In "courses" table we have course_id: 1, title: French
course_id: 9, title: Spanish
User enters: "John"
In ArrayList "results" I store:
prof_id: 5, course_id: 1 and prof_id: 5, course_id: 9
So it's similar with the bridge table, but only contains the info regarding "John".
In String cs[] I want to store all the courses of "John", so cs[] = {"French", "Spanish"}
All in all I want to take only the "title" fields from ArrayList "courses" and store them into a String array (cs[]).
In JSP I would display the titles:
Expand|Select|Wrap|Line Numbers
- <%
- //all the courses that a professor has
- String titles[] = CourseAssignments.getInstance().bridge1("John");
- %>
- <html>
- <head></head>
- <body>
- <center>
- <table border="1" cellspacing="1" cellpadding="8" bgcolor= "33FFCC">
- <tr>
- <td bgcolor= #FF9966><b>Course</b></td>
- </tr>
- <%
- for (int i = 0; i < titles.length; i++){
- if(titles[i] != null){
- %>
- <tr>
- <td><%= titles[i]%></td>
- </tr>
- <%
- }
- }
- %>
- </table>
org.apache.jasper.JasperException: java.lang.NullPointerException