Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 An Overview of Servlet and JSP Technology.

Similar presentations


Presentation on theme: "Chapter 2 An Overview of Servlet and JSP Technology."— Presentation transcript:

1 Chapter 2 An Overview of Servlet and JSP Technology

2 Contents 1.Building Web Pages Dynamically 2.Understanding the Role of Servlets 3.Understanding the Role of JSPs 4.Servlet Jobs 5.Comparing Servlet and JSP

3 1. Building Web Pages Dynamically The Web page is based on data sent by the client The Web page is derived from data that changes frequently

4 2. Understanding the Role of Servlets 2.1. Servlets 2.2. Problem: Displaying Even Numbers

5 2.1. Servlets Java programs that run on Web or application servers The role of web middleware Acting as a middle layer between requests coming from Web browsers or other HTTP clients and databases or applications on the HTTP server

6 2.2. Problem: Displaying Even Numbers Develop a servlet that shows all even numbers from 1 to 100 as shown below:

7 Solution Project name: EvenNumbers Package name: evennumbers 2.2.1. Developing the Servlet Class 2.2.2. Deploying the Servlet to the Web Server

8 2.2.1. Developing the Servlet Class

9 2.2.2. Deploying the Servlet to the Web Server Save EvenNumbersServlet.class to TOMCAT_DIR/webapps/ROOT/WEB- INF/classes/evennumbers/ Declaring EvenNumbersServlet in web.xml

10 3. Understanding the Role of JSPs 3.1. JSPs 3.2. Problem: Displaying Even Numbers

11 3.1. The role of JSP HTML pages with Java code embedded inside  Simplifying the creation and maintenance of the HTML

12 3.2. Problem: Displaying Even Numbers Develop a JSP that shows all even numbers from 1 to 100 as shown below:

13 Solution Save EvenNumbers.jsp to TOMCAT_DIR/webapps/ROOT

14 4. Servlet Jobs Read the explicit data sent by the client. Read the implicit HTTP request data sent by the browser. Generate the results. Send the explicit data (i.e., the document) to the client. Send the implicit HTTP response data.

15 5. Comparing Servlet and JSP ServletJSP Java programs with HTML embedded inside of them HTML pages with Java code embedded inside of them Mostly like a regular Java class Mostly like a normal HTML page The servlets get compiled JSP pages get translated into servlets Run at request time

16 Using Servlet and JSP technology JSP is focused on simplifying the creation and maintenance of the HTML Servlets are best at invoking the business logic and performing complicated operations Servlets are best for tasks oriented toward processing, whereas JSP is best for tasks oriented toward presentation For still others, neither servlets alone nor JSP alone is best, and a combination of the two (see Chapter 15, "Integrating Servlets and JSP: The Model View Controller (MVC) Architecture") is best.Chapter 15

17 References 1.Core Servlets And Java Server Pages, Volume 1, 2 nd Edition, Chapter 2

18 Practice Exercises 1. Create a JSP page that shows all of characters from ‘A’ to ‘Z’ 2. Create a JSP page that show all prime numbers from 1 to 100. 3. Create a Servlet page that show all perfect numbers from 1 to 1000. (a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself. For example: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14 ) positive integerdivisors


Download ppt "Chapter 2 An Overview of Servlet and JSP Technology."

Similar presentations


Ads by Google