A Gentle Introduction to Java Server Pages

Similar documents
Session 11. Expression Language (EL) Reading

Session 21. Expression Languages. Reading. Java EE 7 Chapter 9 in the Tutorial. Session 21 Expression Languages 11/7/ Robert Kelly,

JavaServer Pages and the Expression Language

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

Unit 4 Java Server Pages

JSP - SYNTAX. Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP:

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

Java Server Pages. JSP Part II

Fast Track to Java EE

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

sessionx Desarrollo de Aplicaciones en Red EL (2) EL (1) Implicit objects in EL Literals José Rafael Rojano Cáceres

Server-side Web Programming

ADVANCED JAVA COURSE CURRICULUM

JSP. Basic Elements. For a Tutorial, see:

DVS WEB INFOTECH DEVELOPMENT TRAINING RESEARCH CENTER

COMP9321 Web Application Engineering

COMP9321 Web Application Engineering

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

Trabalhando com JavaServer Pages (JSP)

Java Server Page (JSP)

JavaServer Pages. What is JavaServer Pages?

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

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

Java Server Pages, JSP

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

COMP9321 Web Application Engineering

Trabalhando com JavaServer Pages (JSP)

Advanced Java Programming

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

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

LTBP INDUSTRIAL TRAINING INSTITUTE

Oracle 10g: Build J2EE Applications

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

Introduction to JSP and Servlets Training 5-days

01KPS BF Progettazione di applicazioni web

112-WL. Introduction to JSP with WebLogic

About the Authors. Who Should Read This Book. How This Book Is Organized

Adv. Web Technology 3) Java Server Pages

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

1. Introduction. 2. Life Cycle Why JSP is preferred over Servlets? 2.1. Translation. Java Server Pages (JSP) THETOPPERSWAY.

LTBP INDUSTRIAL TRAINING INSTITUTE

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

112. Introduction to JSP

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

Unit 5 JSP (Java Server Pages)

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

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

EJB ENTERPRISE JAVA BEANS INTRODUCTION TO ENTERPRISE JAVA BEANS, JAVA'S SERVER SIDE COMPONENT TECHNOLOGY. EJB Enterprise Java

/ / JAVA TRAINING

Course Content for Java J2EE

CE212 Web Application Programming Part 3

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

Specialized - Mastering JEE 7 Web Application Development

Table of Contents. Introduction... xxi

Web applications and JSP. Carl Nettelblad

CO Java EE 7: Back-End Server Application Development

JAVA 2 ENTERPRISE EDITION (J2EE)

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

What's New in the Servlet and JSP Specifications

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

SNS COLLEGE OF ENGINEERING, Coimbatore

ive JAVA EE C u r r i c u l u m

Module 5 Developing with JavaServer Pages Technology

Scope and State Handling in JSP

GUJARAT TECHNOLOGICAL UNIVERSITY

Courses For Event Java Advanced Summer Training 2018

Java 2 Platform, Enterprise Edition: Platform and Component Specifications

NetBeans IDE Field Guide

JSP - ACTIONS. There is only one syntax for the Action element, as it conforms to the XML standard:

Java EE 7: Back-End Server Application Development

JavaServer Pages (JSP)

JSP MOCK TEST JSP MOCK TEST IV

Developing Applications with Java EE 6 on WebLogic Server 12c

SUN Enterprise Development with iplanet Application Server

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

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

Deccansoft Software Services. J2EE Syllabus

Experiment No: Group B_2

Table of Contents Fast Track to Java EE 5 with Servlets/JSP and JDBC

The team that wrote this redbook

Java Training For Six Weeks

JBoss to Geronimo - EJB-Session Beans Migration

Core Java. Basics of Java. String Handling. OOPS Concepts. Exception Handling

Test Composition. Performance Summary

CS506 Web Design & Development Final Term Solved MCQs with Reference

AN ISO 9001:2008 CERTIFIED COMPANY ADVANCED. Java TRAINING.

web.xml Deployment Descriptor Elements

Basic Principles of JSPs

SUN Sun Certified Enterprise Architect for J2EE 5. Download Full Version :

IBD Intergiciels et Bases de Données

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions

Building Web Applications in WebLogic

Peers Techno log ies Pv t. L td. Core Java & Core Java &Adv Adv Java Java

More JSP. Advanced Topics in Java. Khalid Azim Mughal Version date: ATIJ More JSP 1/42

Seam 3. Pete Muir JBoss, a Division of Red Hat

Outline. Project Goal. Overview of J2EE. J2EE Architecture. J2EE Container. San H. Aung 26 September, 2003

Module 3 Web Component

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

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.

Distributed Multitiered Application

Transcription:

A Gentle Introduction to Java Server Pages John Selmys Seneca College July 2010

What is JSP? Tool for developing dynamic web pages developed by SUN (now Oracle) High-level abstraction of Java Servlets - extension to Java Servlets Combination of Java Scriptlets and a markup language such as HTML Server side scripting language Current version is 2.1 as of July 2010

A Java Server Page Java code embedded into a HTML page capable of generating dynamic content Syntax takes the form of JSP tags File extension becomes.jsp Application server compiles, loads and executes the Java code First page view (generation) may be slow but succeeding ones are much faster

Application Server Capable of running JSP Apache Tomcat IBM Websphere Oracle Glassfish Redhat Jboss Eclipse Jetty Apple WebObjects Adobe Jrun

JSP Syntax XML-like tags are the syntax of JSP Start with < and end with > Similar to HTML tags Start tag body End tag May be predefined beginning with jsp: May be loaded from a tag library

JSP Elements Directive Declaration Scriptlet Expression Comment Action Custom

JSP Directives <%@... %> Instructs the app server (JSP engine) how to set up this java server page Examples <%@ page language= java %> <%@ include file= url %> <%@ taglib uri= uri-to-taglib %>

JSP Declarations <%!... %> Declares variables and methods to be used in later java code Examples <%! int i = 0; %> <%! Apple anapple = new Apple( red ); %> <%! int AddNumbers(int x, int y) { return x+y; } %> <%! char c; %>

JSP Scriptlets <%... %> Contains Java code fragments Example <% out.println( Hello World! ); %> <% String name = request.getparameter( name ); if(name!= null && name.length() > 0) { %> <%@ include file = answer.jsp %> <% } %>

JSP Expressions <%=... %> Value of expression is converted to a string and inserted into the data stream sent to the client. Examples <%= 2+2 %> <%= 2==2 %> <%= new java.util.date() %> <%= request.getremotehost() %> <%= (int)(math.random()*100)+1 %>

JSP Comments <%--... --%> Some comments may be visible to the client while others are not Examples <%-- Comment is not visible on client --%> <%-- Comment is visible on client >

JSP Action Tag <jsp:action... /> Actions are built into the servlet container adding functionality to ease development. include param forward plugin fallback getproperty setproperty usebean

JSP Action Tag <jsp:action... /> Examples <jsp:include page= first.jsp /> <jsp:forward page= checkout.jsp /> <jsp:usebean id= mybean class= org.example.mybean scope= session /> <jsp:getproperty name= mybean property= myproperty />

JSP Custom Tag <prefix:name... /> User defined language element Examples <%@ taglib uri= mytags prefix= ct %> <ct:getname name= thename %>

JSP Implicit Objects CLASS/INTERFACE javax.servlet.servletcontext javax.servlet.servletconfig java.language.throwable javax.servlet.jsp.jspwriter java.language.object javax.servlet.jsp.pagecontext javax.servlet.servletrequest javax.servlet.servletresponse javax.servlet.http.httpsession application config exception out page PageContext request response session OBJECT

application Used to share data between all JSP Examples: application.getattribute( name ); application.getmajorversion(); application.getserverinfo(); application.setvalue( servername, abc.com );

config Used to pass config data to servlet during initialization Example: Data is defined in web.xml file config.getinitparameter( colour );

exception Used for exception handling Example: www.easywayserver.com

out Used to send output to client Examples: out.write("hello World!"); out.clear(); out.newline(); out.flush();

page Is a reference to the current JSP essentially this Not normally used

PageContext Used to get and put scope data relating to the current JSP Four scopes page data destroyed when JSP completes request data destroyed when request completes session data destroyed when session is destroyed application data destroyed when web application is destroyed

PageContext Example: www.roseindia.net

request Used to get data that the client passed to the server during a HTTP request. Data such as Cookie Header Attribute (returns an object) Method Parameter (returns a string) etc.

request Example: www.roseindia.net Example: www.easywayserver.com Example: www.easywayserver.com

response Used to send a response back to the client Creating cookies Creating HTTP headers Setting content type Redirecting work flow

response Examples: response.sendredirect("http://yahoo.com"); response.setcontenttype("application/pdf"); response.addcookie(cookie roseindia) ; response.addheader("author", "Seneca") ;

session Used to store data associated with a particular user session Example: www.easywayserver.com

Expression Language (EL) A scripting language Access to JavaBeans through JSP Available since JSP 2.0 Use servlet to populate your bean Use redirect forward to xfer control to JSP Use EL to use the bean

Expression Language (EL) To access the bean inside your JSP use either <jsp:usebean id="b" class="mybean" scope="application" /> If bean does not exist it will be created <jsp:include page="/myservlet" />

Expression Language (EL) Syntax ${... } Expression is inside the braces Value is computed and inserted into output stream Container finds variables by scope page, request, session, and application Variables can even be other objects

Expression Language (EL) Variables on LHS of dot are Beans or Maps which use (key,value) for access

Expression Language (EL) Implicit Objects pagescope requestscope sessionscope applicationscope parm parmvalues header headervalues cookie initparam pagecontext

Expression Language (EL) The [... ] operator LHS can be a bean, map, list, array... is a string so use If LHS is a Bean then... is a property Map then... is a unique key Array then... is an index List then... is an index

Expression Language (EL) Examples <%= request.getheader( host ) %> ${header[ host ]} ${header.host}

Expression Language (EL) Literals Boolean: true and false Integer: as in Java Floating point: as in Java String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\. Null: null

Expression Language (EL) Operators (other than dot and [ ] ) Arithmetic: +, - (binary), *, / and div, % and mod, - (unary) Logical: and, &&, or,, not,! Relational: ==, eq,!=, ne, <, lt, >, gt, <=, ge, >=, le Empty: Conditional: A? B : C

Expression Language (EL) Precedence high to low and left [ ]. ( ) - (unary) not! Empty * / div % mod + - (binary) < > <= >= lt gt le ge ==!= eq ne && and or? :

Expression Language (EL) Reserved Words and eq gt true instanceof or ne le false empty not lt ge null div mod

Beans JavaBean: reusable software components for Java that can be manipulated visually in a builder tool EJB: server-side model that encapsulates the business logic of an application

Enterprise Java Beans Have public default constructors May have get/set methods Properties are optional May require serialization

EJB Container Provides Component pooling Resource management Transaction management Security Persistence Client management

EJB Containers Apache Geronimo Oracle Glassfish Adobe Jrun Red Hat Jboss IBM Websphere Eclipse Jetty

Enterprise Java Beans Types 1. Session 2. Message-Driven 3. JPA (Java Persistence API) EJB 3.0 Replaces CMP (Container Managed Persistence) Replaces Entity bean 4. Multimedia (future?)

Session Bean Created by client Exists on the server inside the EJB container Performs functions for the client eg. database access eg. computations Destroyed when session ends

Session Bean Stateless Statefull Can be thought of as the same bean used by all users (sessions). Allows concurrent access to the bean Each session has its own copy of the bean Instance variables hold the state of the bean

Stateless Session Bean Example: openejb.apache.org EJB 3.0 uses annotations no need for deployment descriptor file (ejb-jar.xml) Must implement local or remote interfaces or both

Example Developing a Simple Calculator Web Service cwiki.apache.org

Example Accessing EJB in Web applications cwiki.apache.org

Message-Driven Beans Use JMS (Java Message Service) technology Allows J2EE applications to process messages asynchronously Similar to event-driven paradigm Messages may be sent by any J2EE component application client another enterprise bean others

Example Message-Driven Beans www.thedevinfo.com

JPA Beans Java Persistent API Framework to manage relational data in J2EE applications Entity beans give persistent access to database tables Geronimo uses OpenJPA

Example Developing bean managed persistence with JPA cwiki.apache.org