Presentation is loading. Please wait.

Presentation is loading. Please wait.

JSP / Servlets and Beans

Similar presentations


Presentation on theme: "JSP / Servlets and Beans"— Presentation transcript:

1 JSP / Servlets and Beans
JSP Advantages Separation of Static from Dynamic content Write once run anywhere Dynamic content can be run anywhere (web server independent)

2 JSP or Servlets? Servlets should be used strictly as a web server extension. This could include controller components offering services like authentication, database validation, etc. It is interesting to note that what is commonly known as a JSP engine is itself a specialized servlet running under the control of the servlet engine.

3 JSP Architecture init event JspInit() Request response JspService()
A JSP page is compiled only once. After that the JSP engine uses the same class file to serve other requests to that file. The page is recompiled ONLY if changes have been made to the JSP page init event Request response Destroy event JspInit() JspService() jspDestroy() jsp “servlet”

4 JSP Access Models Model 1 Architecture 1 database JSP browser 4 2 3
request browser JSP 4 response 2 Java Bean 3

5 Analysis In model 1 architecture the incoming request from the Browser is set directly to the JSP page which is responsible for processing it and replying back to the client. Beans may be used to connect to databases etc to keep the content separate from the design. Suitable for simple applications.

6 JSP Access Models Model 2 Architecture MVC design pattern database
browser Servlet (Controller) 1 request instantiate 3 2 5 response JSP (View) Java Bean (Model) 4

7 Analysis Processing is divided between presentation and front components. Main Advantage is that there is no processing logic with the presentation component. This leads to clear delineation of the roles of the developers/ programmers. The front component makes the present a single point of entry into the application making the management of the application state, security and presentation uniform.

8 Example for Model 1

9 HTML page

10 JSP page

11 Bean

12 Example for Model 2

13 HTML Code

14 Servlet Code (getinfo)

15 Bean Code (getdataBean)

16 Bean Code Contd.. (getdataBean)

17 JSP Code (showinfo)

18 References JAVA 2 The Complete Reference
JSP Architecture (chapter 12) from copy of the article at : Fundamentals of Java Servlets: The Java Servlet API JavaServerPages Fundamentals :Short Course

19 Thank You 


Download ppt "JSP / Servlets and Beans"

Similar presentations


Ads by Google