Introduction to Java Server Pages (JSPs) Robert Thornton.

Slides:



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

Java Server Pages (JSP)
Java Server Pages Jeffrey Jongko. Introduction Java Server Pages (JSP) technology was created by Sun Microsystems and is built on top of Sun’s Java Servlet.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
Michael Brockway Application Integration JavaServer Pages l Introduction & Overview l Implicit Objects l Scripting l Standard Actions l Directives l References.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
CS320 Web and Internet Programming JSP Scripting Elements and Page Directives Chengyu Sun California State University, Los Angeles.
JSP Java Server Pages Reference:
DT228/3 Web Development JSP: Directives and Scripting elements.
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,
1 CS6320 – JSP L. Grewe 2 Java Server Pages Servlets require you to write out entire page delivered with print statements Servlets require you to write.
Web programming for project students Dr Jim Briggs.
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.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
ASHIMA KALRA.  INTRODUCTION TO JSP INTRODUCTION TO JSP  IMPLICIT OBJECTS IMPLICIT OBJECTS  COOKIES COOKIES.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
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.
Slides © Marty Hall, book © Sun Microsystems Press 1 JSP Scripting Elements Core Servlets & JSP book:
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
Chapter 7 Being a JSP. JSP introduction JSP is a solution for two issues  Servlet is difficult for HTML designers since they may not know Java  Formatting.
intro JSP Pertemuan 8 Matakuliah: Web Programming Tahun: 2009.
SE-2840 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
CS-4220 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
JSP. Types of JSP Scripting Elements Expressions of the form, which are evaluated and inserted into the servlet's output. Scriptlets of the form, which.
Web Technologies Java Beans & JSP By Praveen Kumar G.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
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.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
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.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
 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,
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
JSP Elements Chapter 2.
Developing JavaServer Pages
Java Server Pages.
Pre-assessment Questions
Introduction to JSP Java Server Pages
Knowledge Byte In this section, you will learn about:
Chengyu Sun California State University, Los Angeles
Invoking Java Code from JSP
JSP Directives 1-Jan-19.
COP 4610L: Applications in the Enterprise Spring 2005
JSP implicit objects & directive elements
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction.
Presentation transcript:

Introduction to Java Server Pages (JSPs) Robert Thornton

Notes This is a training NOT a presentation Please ask questions Prerequisites – Basic Java and HTML skills. – Installed LDSTech IDE (or other equivalent). – Installed App Server (such as Tomcat).

Overview Java Server Pages What are they? What is their role? JSP Programming Fundamentals: Directives Declarations Expressions, Scriptlets, and implicit objects. Error handling Maven JSP Compiler What does a compiled JSP look like?

What is a JSP really? A text document containing: – Static data (usually HTML) – JSP elements that construct dynamic content – Typically ends with a.jsp extension Translated into a Java class – Extends HttpServlet – May be compiled as part of a build or compiled at runtime in response to a detected change.

What is the role of a JSP? Provides the view of MVC. Allows generation of static HTML using familiar web tools and syntax. Allows generation of dynamic HTML using familiar Java syntax and language features. Allows rapid prototyping of web pages.

JSPs versus Java Servlets Java Servlets: – Strictly written in Java – HTML must be embedded and escaped within Java strings literals. – Must be defined and mapped within web.xml Java Server Pages (JSPs) – Mostly static HTML with JSP elements. – No servlet definitions or mappings necessary.

JSP Example 1 JSP Training: Example 1 Hello World! The current date is

Lab 1: JSP Servlet Compilation Lab 1 _1:_JSP_Servlet_Compilation

JSP Elements: Directives Directives allow control over how the JSP is translated into a servlet. Three types of directives: – Page: defines attributes that affect the structure and definition of the generated servlet. – Include: statically includes the contents of other files in the JSP (covered in a later training). – Taglib: imports a JSP tag library for use by the page (also covered in a later training).

JSP Elements: Page Directive Example syntax: page contentType="text/html" pageEncoding="UTF-8" errorPage="error.jsp" import="java.util.*" %> A page directive may appear anywhere in the JSP. A page directive may appear multiple times.

JSP Elements: Page Directive Attributes contentType – The value passed to ServletResponse.setContentType pageEncoding – The value passed to ServletResponse.setCharacterEncoding import – Import statements to include in the generated servlet errorPage – Relative path to an error page if an exception is thrown isErrorPage – Whether this page is to handle exceptions from other pages

JSP Elements: Page Directive Examples page contentType="text/html" pageEncoding="UTF-8" %> page import="java.util.Date" import="java.text.SimpleDateFormat" import="java.io.*,java.net.*" import="static org.lds.stack.Constants.*" %>

JSP Elements: Comments Syntax: Can be used to comment out both JSP and HTML elements. JSP comments will be ignored by the JSP parser and will not included in the generated servlet.

JSP Elements: Declarations Syntax: May contain one or more Java declarations to be inserted into the class body of the generated servlet. May be used multiple times to declare both member variables and helper functions on the generated servlet.

JSP Elements: Example Declarations <%! private final int FOO = 1024; private String[] options = { "green", "red", "blue", "yellow" }; %> <%! private String doSomething(HttpServletRequest req) { // do something } %>

JSP Elements: Scriptlets Syntax: Consists of one or more Java statements to be inserted into the generated servlet’s _jspService method (called by service ). Each scriptlet will be inserted after streaming any preceding static content and before streaming any subsequent static content.

JSP Elements: Example Scriptlets <% String[] options = { "green", "red", "blue", "yellow" }; %>

Lab 2: Hello World in JSP Lab 2 _2:_Hello_World_in_JSP

JSP Elements: Expressions Syntax: Consists of Java code to be evaluated and written to the response output stream during the evaluation of the _jspService method. Expression return type must not be void. Each expression’s output will be inserted into the output stream after any preceding static content and before any subsequent static content.

JSP Elements: Example Scriptlets <% String[] options = { "green", "red", "blue", "yellow" }; %> ">

JSP Elements: Implicit Objects Implicit objects are variables available to both expressions and scriptlets. They are not available within declarations. They are, in fact, local variables of the _jspService method.

JSP Elements: Implicit Objects request – javax.servlet.http.HttpServletRequest response – javax.servlet.http.HttpServletResponse session – javax.servlet.http.HttpSession application – javax.servlet.ServletContext config – javax.servlet.ServletConfig out – javax.servlet.jsp.JspWriter pageContext – javax.servlet.jsp.PageContext exception – java.lang.Throwable

Lab 3: A JSP Calendar Lab 3 _3:_A_JSP_Calendar

Using Maven to Compile JSPs Maven can be used to validate and pre-compile JSPs before deploying them to a server. This protects against inadvertently sending broken pages to the server. This can also be used to analyze bugs how changes in the JSP affect the compiled servlet JSP Servlets generated by the maven build will not necessarily match JSP servlets generated by the application server.

Lab 4: Pre-compiling JSPs with Maven Lab 4 _4:_Pre-compiling_JSPs_with_Maven

Credit where credit is due Core Servlets and JavaServer Pages, Marty Hall and Larry Brown, Sun Microsystems & Prentice Hall, 2000 – ISBN-13: