8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Advertisements

Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) Customer Supplier Customer authorizes Enrollment ( )
19 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Developing Web Services.
21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
1 Copyright © 2005, Oracle. All rights reserved. Introduction.
7 Copyright © 2005, Oracle. All rights reserved. Maintaining State in J2EE Applications.
18 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Introduction to Web Services.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
16 Copyright © 2005, Oracle. All rights reserved. Developing Message-Driven Beans.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
6 Copyright © 2005, Oracle. All rights reserved. Using Advanced Techniques in Servlets.
3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
J2EE Overview.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
17 Copyright © 2005, Oracle. All rights reserved. Deploying Applications by Using Java Web Start.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Analyzing Genes and Genomes
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts
CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaServer Page.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
1 Chapter 27 JavaServer Page. 2 Objectives F To know what is a JSP page is processed (§27.2). F To comprehend how a JSP page is processed (§27.3). F To.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
JSP JavaServer Pages. What is JSP? Java based technology that simplifies the development of dynamic web sites JSP pages are HTML pages with embedded code.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
JSP implicit objects & directive elements
Presentation transcript:

8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages

8-2 Copyright © 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Compare servlets and JavaServer Pages (JSP) Build a simple JSP Describe the JSP life cycle List the basic JSP elements Develop JSPs with declarations, expressions, and scriptlets List implicit objects Use JavaBeans with JSP

8-3 Copyright © 2005, Oracle. All rights reserved. JavaServer Pages Generates Dynamic content JSP Connects to EJB Client Request Database Response

8-4 Copyright © 2005, Oracle. All rights reserved. Comparing Servlets and JSPs Servlets: Are Java programs with embedded HTML Generate dynamic content Do not separate static and dynamic content JavaServer Pages: Are HTML pages with embedded Java code or they can be pure XML Generate dynamic content Separate static and dynamic content

8-5 Copyright © 2005, Oracle. All rights reserved. Invoking JSPs HTML JSP Invoke Servlet JSP

8-6 Copyright © 2005, Oracle. All rights reserved. The Date JSP Show Date The current time is:

8-7 Copyright © 2005, Oracle. All rights reserved. The Date Servlet... public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); out.println(" "); out.println(" Show Date The current time is: "); out.println(new java.util.Date()); out.println(" "); out.close(); }...

8-8 Copyright © 2005, Oracle. All rights reserved. Automated JSP Features A JSP is automatically converted into a servlet the first time it is invoked: –Java source files are generated. –Java class files are generated. –The Java Just-In-Time compiler can be used. A JSP can contain extensible components: –Tags: Libraries such as OC4J JSP (OJSP) or custom-developed tags. –JavaBeans (Beans are reused and their properties are automatically introspected.)

8-9 Copyright © 2005, Oracle. All rights reserved. JSP Life Cycle J2EE container Create servlet date.java Compile servlet date.class 1 Servlet life cycle First time Yes 2 3 No OC4J

8-10 Copyright © 2005, Oracle. All rights reserved. Basic JSP Elements A JSP contains three main elements: Text elements Directives Scripting elements –Declarations –Expressions –Scriptlets

8-11 Copyright © 2005, Oracle. All rights reserved. Declarations Are used to define methods or variables Begin with the sequence <%! End with the sequence %> Are inserted into the body of the servlet class during translation Are used in conjunction with expressions or scriptlets

8-12 Copyright © 2005, Oracle. All rights reserved. Expressions Begin with the sequence <%= Contain Java expressions that are evaluated and inserted into the servlets output End with the sequence %> Do not end with a semicolon 1 2

8-13 Copyright © 2005, Oracle. All rights reserved. Scriptlets Begin with the sequence <% Contain a block of Java code that is executed every time a request is made End with the sequence %> <% if (i<3) out.print("i<3"); if (i==3) out.print("i==3"); else out.print("i>3"); %>

8-14 Copyright © 2005, Oracle. All rights reserved. Implicit Objects There are eight implicit objects, also known as predefined variables, in JSP: request response session out application config pageContext page

8-15 Copyright © 2005, Oracle. All rights reserved.

8-16 Copyright © 2005, Oracle. All rights reserved. Example

8-17 Copyright © 2005, Oracle. All rights reserved.

8-18 Copyright © 2005, Oracle. All rights reserved. Directives Are used to set global values such as class declaration, method implementations, and so on Begin with the sequence End with the sequence %> Are of the following types: – page – include – taglib

8-19 Copyright © 2005, Oracle. All rights reserved. include : Example

8-20 Copyright © 2005, Oracle. All rights reserved. page Directive You can define the following attributes by using the page directive: import contentType isThreadSafe session buffer autoflush extends info errorPage isErrorPage language

8-21 Copyright © 2005, Oracle. All rights reserved.

8-22 Copyright © 2005, Oracle. All rights reserved. JSP and JavaBeans package lesson08; import java.lang.*; import java.util.*; public class LuckyNumberBean { private int luckyNum; public LuckyNumberBean() { luckyNum = (int) (1000 * Math.random()); } public int getLuckyNum() { return luckyNum; } public void setLuckyNum(int luckyNum) { this.luckyNum = luckyNum; }

8-23 Copyright © 2005, Oracle. All rights reserved. Using JavaBeans with JSP Accessing JavaBeans with the tag:

8-24 Copyright © 2005, Oracle. All rights reserved.

8-25 Copyright © 2005, Oracle. All rights reserved. scope Attribute of Tag Client Page 1 Page 2 Page 3 Request Forward Response Request Response page scope request scope session scope

8-26 Copyright © 2005, Oracle. All rights reserved. Accessing and Setting Bean Property Accessing bean property: Setting bean property:

8-27 Copyright © 2005, Oracle. All rights reserved.

8-28 Copyright © 2005, Oracle. All rights reserved. JSP XML Document Contains as its root element Includes only XML syntax and does not include the traditional JSP tags Can be processed directly by the JSP container Can be used with XML development tools

8-29 Copyright © 2005, Oracle. All rights reserved. Traditional Syntax Versus XML Syntax Traditional:XML: No root element page directive Declaration tag Expression tag Scriptlet is the root element

8-30 Copyright © 2005, Oracle. All rights reserved.

8-31 Copyright © 2005, Oracle. All rights reserved. JDeveloper and JSPs Use the JSP Wizard in JDeveloper to create JSPs containing skeleton code. The structure pane helps to ensure that the JSP and HTML tags are properly formatted. Tag Insight automatically inserts end tags after starting a scriptlet. JSP code is automatically created and recompiled. JDeveloper increases productivity while debugging JSPs: –Automatically includes source Java files such as your JavaBean source –Enables you to set breakpoints and watch expressions in JSPs

8-32 Copyright © 2005, Oracle. All rights reserved. Creating JSPs Visually

8-33 Copyright © 2005, Oracle. All rights reserved. JSP Tag Insight

8-34 Copyright © 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Differentiate between servlets and JSPs Build a simple JSP Describe the JSP life cycle Use JSP elements and implicit objects Develop JSPs with declarations, expressions, and scriptlets Use JavaBeans with JSP

8-35 Copyright © 2005, Oracle. All rights reserved. Practices 8-1, 8-2, and 8-3: Overview These practices cover the following topics: Creating a JSP that counts the occurrence of each character in a given string Using JavaBean to calculate an equal discount on the total amount of purchase Creating a JSP that displays product_id, product_name, and price in the form of a table

8-36 Copyright © 2005, Oracle. All rights reserved.

8-37 Copyright © 2005, Oracle. All rights reserved.

8-38 Copyright © 2005, Oracle. All rights reserved.

8-39 Copyright © 2005, Oracle. All rights reserved.

8-40 Copyright © 2005, Oracle. All rights reserved.