Presentation is loading. Please wait.

Presentation is loading. Please wait.

CourseOutline Example & JavaBeans Lec - 36. Start with Example Displaying Course Outlines User will select either course “web design & development” or.

Similar presentations


Presentation on theme: "CourseOutline Example & JavaBeans Lec - 36. Start with Example Displaying Course Outlines User will select either course “web design & development” or."— Presentation transcript:

1 CourseOutline Example & JavaBeans Lec - 36

2 Start with Example Displaying Course Outlines User will select either course “web design & development” or “java”. On submitting request, course outline would be displayed of the selected course from database

3 Program Flow index.jsp controller.jsp web.jsp java.jsp If page = = web If page = = java

4 Issues with Last Example Too much cluttered code in JSP –Difficult to understand A single page is doing everything – bad approach –Displaying contents (Presentation logic) –Connecting with database (DB connectivity logic) –Results Processing (Business Logic) Solution: –Use JavaBeans

5 JavaBeans

6 What are JavaBeans? Java class that can be easily reused and composed together in an application Any java class that follows certain design conventions can be a JavaBeans component

7 JavaBeans Design Conventions A bean class must have a zero argument constructor A bean class should not have any public instance variables (fields) Private values should be accessed through setters/getters –For boolean data types, use boolean isXXX( ) & setXXX(boolean) A bean class must be serializable

8 A Sample JavaBean public class MyBean implements Serializable { private String name; // zero argument constructor public MyBean( ){ name = “”; } // standard setter public void setName(String n) { name = n; }

9 A Sample JavaBean cont. // standard getter public String getName( ) { return name; } // any other method public void print( ) { System.out.println(“Name is: ” + name); } } // end Bean class

10 Incorporating Bean in Last Example Create a CourseOutlineBean –Has following attributes sessionNo topic assignment Create a CourseDAO (bean) –Encapsualte database connectivity logic web.jsp & java.jsp will use these beans

11 Example Code Incorporating JavaBeans in CourseOutline Example


Download ppt "CourseOutline Example & JavaBeans Lec - 36. Start with Example Displaying Course Outlines User will select either course “web design & development” or."

Similar presentations


Ads by Google