Day 13. JavaServer Pages

Yesterday, you looked at developing Web applications using Java servlets. Servlets have the advantage of being able to generate the HTML Web page dynamically. The disadvantage of servlets is the developer must generate the HTML formatting information from within Java, and this means a lot of out.println statements. Servlets can be described as large amounts of boring HTML statements interspersed with small amounts of interesting Java code.

Servlets make it difficult to differentiate the presentation layer from the logic layer of an application. This duality of purpose means that servlets do not allow the roles of HTML designer and Java programmer to be easily separated. Writing servlets requires the members of the development team to be either

  • Java programmers who must learn HTML and Web design

  • Web designers who must learn Java

In practice, the roles of Web designer and Java programmer are sufficiently different to ensure that there are very few Java programmers who make good Web designers, and similarly few Web designers who make good Java programmers.

Fortunately, there is a solution. JavaServer Pages are another way of providing servlets that are written within the HTML page. Actually, there is a bit more to it than that, but any Java code on a JSP is usually either non-existent or very simple, and can be readily understood by non-Java programmers.

Typically, as discussed on Day 2, “The Java Platform and Roles,” servlets and JSPs are both used in a Web Application to take advantage of the strengths of each topic. This subject is discussed in more detail in the section “Web Application Architecture” at the end of today's work.,

First, you need to understand the capabilities of JSPs. In today's lesson, you will

  • Examine the differences between a JSP and a normal servlet

  • Be introduced to the Element Language (EL) used to add programming elements to a JSP

  • Study the JSP lifecycle and what the Web server carries out on your behalf

  • Learn how to deploy a JSP

  • Learn how to use JavaBeans to hide Java functionality from the JSP

  • Learn how to develop a Web application using JSPs

NOTE

The Element Language (EL) was introduced with the early access version of JSTL (see Day 14, “JSP Tag Libraries”) and was retrofitted into the emerging JSP 2.0 specification. If you are using a J2EE 1.3 compliant server it will not support EL and you will have to use the alternative syntax shown in examples for today and tomorrow.


Today's work builds directly on the knowledge gained yesterday because many of the mechanisms used in JSPs are the same as servlets.,

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.195.28