Module 5 Developing with JavaServer Pages Technology

Similar documents
Module 3 Web Component

112. Introduction to JSP

112-WL. Introduction to JSP with WebLogic

Introduction to JSP and Servlets Training 5-days

Advanced Java Programming

Fast Track to Java EE

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

JSP. Basic Elements. For a Tutorial, see:

SUN Enterprise Development with iplanet Application Server

Ch04 JavaServer Pages (JSP)

Fast Track to Java EE 5 with Servlets, JSP & JDBC

Unit 5 JSP (Java Server Pages)

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Oracle 1z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Practice Test. Version:

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

Distributed Multitiered Application

JavaEE Interview Prep

Developing Applications with Java EE 6 on WebLogic Server 12c

web.xml Deployment Descriptor Elements

Anno Accademico Laboratorio di Tecnologie Web. Sviluppo di applicazioni web JSP

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

JavaServer Pages. What is JavaServer Pages?

Vision of J2EE. Why J2EE? Need for. J2EE Suite. J2EE Based Distributed Application Architecture Overview. Umair Javed 1

directive attribute1= value1 attribute2= value2... attributen= valuen %>

Experiment No: Group B_2

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

Introduction to Java Server Pages. Enabling Technologies - Plug-ins Scripted Pages

1 CUSTOM TAG FUNDAMENTALS PREFACE... xiii. ACKNOWLEDGMENTS... xix. Using Custom Tags The JSP File 5. Defining Custom Tags The TLD 6

SESM Components and Techniques

COMP9321 Web Application Engineering

Oracle 10g: Build J2EE Applications

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Java Server Page (JSP)

CHAPTER 1. Core Syntax Reference

Contents at a Glance

A Gentle Introduction to Java Server Pages

01KPS BF Progettazione di applicazioni web

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

A JavaBean is a class file that stores Java code for a JSP

What's New in the Servlet and JSP Specifications

SECTION II: JAVA SERVLETS

Chapter 2 FEATURES AND FACILITIES. SYS-ED/ Computer Education Techniques, Inc.

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

What's New in J2EE 1.4

Test Composition. Performance Summary

Table of Contents. Introduction... xxi

Java 2 Platform, Enterprise Edition: Platform and Component Specifications

AIM. 10 September

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

Modernizing Java Server Pages By Transformation. S h a n n o n X u T h o m a s D e a n Q u e e n s U n i v e r s i t y

Course Content for Java J2EE

COMP9321 Web Application Engineering

Jakarta Struts: An MVC Framework

Courses For Event Java Advanced Summer Training 2018

Specialized - Mastering JEE 7 Web Application Development

Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat

JSP MOCK TEST JSP MOCK TEST IV

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

GUJARAT TECHNOLOGICAL UNIVERSITY

COMP9321 Web Application Engineering

JAVA 2 ENTERPRISE EDITION (J2EE)

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

Web Application Architecture (based J2EE 1.4 Tutorial)

Java SE7 Fundamentals

JAVA MICROSERVICES. Java Language Environment. Java Set Up. Java Fundamentals. Packages. Operations

J2SE, JSP & JavaBeans Web Demonstration of SWKB Program

Enterprise Java Unit 1-Chapter 2 Prof. Sujata Rizal Java EE 6 Architecture, Server and Containers

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Java EE 6: Develop Web Applications with JSF

Université du Québec à Montréal

CS506 Web Design & Development Final Term Solved MCQs with Reference

Call: Core&Advanced Java Springframeworks Course Content:35-40hours Course Outline

JSF. What is JSF (Java Server Faces)?

S imilar to JavaBeans, custom tags provide a way for

JavaServer Pages (JSP)

Advantage of JSP over Servlet

Building the Enterprise

JavaServer Pages and the Expression Language

Java Programming Course Overview. Duration: 35 hours. Price: $900

UNIT -5. Java Server Page

Basic Principles of JSPs

Java J Course Outline

JBoss SOAP Web Services User Guide. Version: M5

Oracle WebLogic Server

Java EE 5 Development for WebSphere Application Server V7

Exercise. (1) Which of the following can not be used as the scope when using a JavaBean with JSP? a. application b. session c. request d.

Scope and State Handling in JSP

Overview p. 1 Server-side Component Architectures p. 3 The Need for a Server-Side Component Architecture p. 4 Server-Side Component Architecture

CHAPTER 6. Organizing Your Development Project. All right, guys! It s time to clean up this town!

ADVANCED JAVA COURSE CURRICULUM

Presentation and content are not always well separated. Most developers are not good at establishing levels of abstraction in JSPs

Struts Lab 3: Creating the View

UNIVERSITY EXAMINATIONS: NOV/DEC 2011 REGULATION PERVASIVE COMPUTING PART A

Component-Based Software Engineering. ECE493-Topic 5 Winter Lecture 26 Java Enterprise (Part D)

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H

UNIT I Java Bean, HTML & Javascript

Web Component Development with Servlet and JSP Technologies, Java EE 6

Transcription:

Module 5 Developing with JavaServer Pages Technology Objectives Evaluate the role of JSP technology as a presentation Mechanism Author JSP pages Process data received from servlets in a JSP page Describe the use of tag libraries 126 Ω Omega Ω 1

JSP Technology as a Presentation Mechanism JSP pages are text-based documents that describe how to process a request and create a response. Using JSP technology, a page designer creates a document to generate dynamic content. JSP elements: Enable external object access Add canned programming capabilities Source files for JSP pages typically end with the.jsp extension. 127 Ω Omega Ω JSP Technology as a Presentation Mechanism JSP technology: Uses beans to interact with server-side objects Uses tag libraries to develop and extend the canned capabilities provided by actions Allows for a high degree of separation between the static and dynamic content in a JSP page Provides (where necessary) a powerful scripting language for JSP pages Is an integral part of the Java EE platform, and so provides front-end access to EJB components 128 Ω Omega Ω 2

Presentation Using JSP Pages Compared to Servlets JSP pages are web components that are based on the servlet model and that run as servlets: 129 Ω Omega Ω Presentation Using JSP Pages Compared to Servlets 130 Ω Omega Ω 3

Worker Beans, JSTL, and Custom Tags You can separate programmatic functionality from presentation in JSP components in two ways: Incorporate classes with the <jsp:usebean> tag and the JSTL: Useful for carrying data into the JSP component JSTL allows programmatic behavior without scriptlets Make use of custom tag libraries: Most valuable when tag libraries are general-purpose and reusable Less useful for page specific logic, such as unique form processing 131 Ω Omega Ω JSP Page Deployment Mechanism JSP pages: Are translated into servlets on demand Can be deployed in the same manner as an HTML page, by copying the file onto the server 132 Ω Omega Ω 4

JSP Page Translation Procedure 133 Ω Omega Ω Java Code Embedded in JSP Pages Ideally, a JSP page should be concerned with presentation logic only. A servlet is a better alternative for processing logic and for flow control. Using scripting code for processing logic and flow control within a JSP page results in problems that include: A JSP page author: Must code well in the scripting language Might need more business domain knowledge It is more difficult to see presentation information when you view the JSP page. Debugging is more difficult because of the added complexity and decreased clarity. 134 Ω Omega Ω 5

Authoring JSP Pages A JSP page contains: Standard markup tags, such as HTML or XML Associated text data A variety of elements that are defined by the JSP specification 135 Ω Omega Ω JSP Page Components 136 Ω Omega Ω 6

Syntactic Forms of JSP Tags Syntactic forms of tags based on JSP tags can be represented in two different ways: 137 Ω Omega Ω JSP Technology Directives Contain information to help a JSP container configure and run a JSP page Are associated with the compiled servlet that is created from the JSP page Do not produce output Have the following generic syntax: <%@ directive attribute="value"... %> 138 Ω Omega Ω 7

JSP Directives 139 Ω Omega Ω The page Directive The page directive defines page-dependent attributes: An attribute and value pair cannot be redefined within a translation unit, with the exception of the include page directive. Redefining a page directive results in a fatal translation error, unless the new and the old definitions are the same. 140 Ω Omega Ω 8

The page Directive Examples using both styles of syntax: <%@ page import="java.util.*, java.lang.*" %> <%@ page buffer="5kb" autoflush="false" %> <jsp:directive.page errorpage="error.jsp" /> 141 Ω Omega Ω JSP page Directives 142 Ω Omega Ω 9

The include Directive The include directive: Inserts the text of the specified resource into the.jsp file at page translation time Treats resources as static objects Can be other HTML files or other JSP pages that contain text, or code, or both Examples of the include directive: <%@ include file="relativeurl" %> Or <jsp:directive.include file="relativeurl" /> 143 Ω Omega Ω The include Directive 144 Ω Omega Ω 10

Declarations, Expressions, and Scriptlets Scripting elements allow a page designer to provide advanced programming capabilities. Scripting elements include: Declarations Expressions Scriptlets 145 Ω Omega Ω Declarations, Expressions, and Scriptlets 146 Ω Omega Ω 11

Declaration Scripting Elements 147 Ω Omega Ω Expression Scripting Elements 148 Ω Omega Ω 12

Scriptlet Scripting Elements 149 Ω Omega Ω Scriptlet Scripting Elements 150 Ω Omega Ω 13

Scriptlet Scripting Elements Translate to 151 Ω Omega Ω Thread-Safety Implications Declarations occur at the instance level of the generated servlet. Therefore: All requests to the JSP page share these variables and methods. Thread-safety problems can occur with this technique. All of the cautions that apply to servlets and threadsafety, apply to JSP page declarations. 152 Ω Omega Ω 14

Processing Data From Servlets The JSP specification defines a standard set of action types that all JSP containers must implement, including: Create or use beans Set and get bean properties Include static and dynamic resources in the current page s context You can define additional action types using custom tag libraries. 153 Ω Omega Ω The jsp:usebean Action Creates or locates an existing bean that matches the criteria in the tag Associates the bean instance with a scope and action ID Makes the ID accessible by scripting elements and custom tags 154 Ω Omega Ω 15

The jsp:usebean Action Syntax of jsp:usebean: <jsp:usebean id="name" scope="scope" typespec /> Alternate syntax with initialization code: <jsp:usebean id="name" scope="scope" typespec> <%...initialization code... %> </jsp:usebean> typespec can be any of the following: class="classname" class="classname" type="typename" beanname="beanname" type=" typename" type="typename" 155 Ω Omega Ω The jsp:usebean Action 156 Ω Omega Ω 16

The jsp:usebean Action This graphic shows the id attribute 157 Ω Omega Ω The jsp:usebean Action Examples of jsp:usebean: Usage example for the id attribute: <jsp:usebean id="account class="bank.account /> To retrieve the account balance, use the expression: <%=account.getbalance() %> 158 Ω Omega Ω 17

The jsp:usebean Scopes 159 Ω Omega Ω Request-Scope Beans and Collecting Data From Servlets The jsp:usebean action is commonly used to share data between servlets and JSP pages. The following is a typical sequence of events involving jsp:usebean: A servlet performs front-end processing. The servlet sets an attribute on the request object. The servlet dispatches to a JSP page to display dynamic data. The JSP uses jsp:usebean with the request scope attribute to collect the data. 160 Ω Omega Ω 18

Request-Scope Beans and Collecting Data From Servlets The following code snippet creates a new Customer object and saves it in a request attribute named customer: 161 Ω Omega Ω Request-Scope Beans and Collecting Data From Servlets The JSP page example.jsp that is illustrated in the following code snippet can then access and process the customer object as follows: 162 Ω Omega Ω 19

The jsp:getproperty Action 163 Ω Omega Ω Custom Tag Libraries Provide an alternative to scriptlets for customizing JSP pages for specific business needs It is preferable to avoid scriptlet code in JSP pages. Use an XML-style tag format to provide canned capabilities to use, modify, or create objects 164 Ω Omega Ω 20

The taglib Directive Extends the set of tags that a JSP container can interpret Associates a tag prefix with a tag library that: Consists of a set of classes and a tag library descriptor Implements the range of operations defined in the tags 165 Ω Omega Ω The taglib Directive Format of the taglib directive: <%@ taglib uri="iterator_tags prefix="iterator"%> Tag library usage: <iterator:iterate> <%-- perform repetitive task --%>... </iterator:iterate> 166 Ω Omega Ω 21

The tag-library Descriptor and Java Classes The URI mapping in the web application deployment descriptor maps a prefix to a TLD. The TLD is an XML file that is usually packaged in the web application or library, along with the classes that implement its range of operations. 167 Ω Omega Ω The tag-library Descriptor and Java Classes Mapping example: In the JSP page: <iterator:iterate id= accounts > Information from the TLD: 168 Ω Omega Ω 22

The Expression Language(EL) The Expression Language is an easy to use language that can be embedded in JSP pages instead of scriptlets (when used with tag libraries). Its syntax is similar to JavaScript and can be learned by non-programmers. ${ 3 + 2 } ${ param.address } ${ requestscope.customer.name } ${ not empty sessionscope.message } 169 Ω Omega Ω JSTL Examples 170 Ω Omega Ω 23

Packaging Tag Libraries in Web Applications With a custom tag library, the tag class must be in the classpath of the class loader. Tag classes can be located in the same directories as regular classes and jar libraries. A Java EE 5 application server implementation can support additional directories when determining the classpath. The standard tag libraries are already present on any Java EE 5 system as JAR files. JSTL JAR files have TLD files embedded in such a way that they do not require them to be listed in the web.xml file. 171 Ω Omega Ω 24