COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.

Slides:



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

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.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
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,
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.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
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 JSP Based on: Marty Hall, Larry Brown, Core Servlets and JavaServer Pages.
JSP Java Server Pages Softsmith Infotech.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
Introduction to Java Server Pages (JSPs) Robert Thornton.
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.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Jordan Anastasiade. All rights reserved.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
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.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
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 (JSP)
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.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
Chapter 11 Invoking Java Code with JSP Scripting Elements.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
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.
Web Technologies Java Beans & JSP By Praveen Kumar G.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
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.
INVOKING JAVA CODE WITH JSP SCRIPTING ELEMENTS. Creating Template Text A large percentage of your JSP document consists of static text (usually HTML),
 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.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
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.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
JSP Java Server Pages. Hello, !
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
CS3220 Web and Internet Programming Introduction to Java Servlets
JSP Based on
COMP9321 Web Application Engineering Semester 2, 2017
Java Servlets.
Scripted Page Web App Development (Java Server Pages)
Knowledge Byte In this section, you will learn about:
CS3220 Web and Internet Programming Introduction to Java Servlets
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.
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week 3

Java Servlets Review: Java Servlets 2COMP9321, 15s2, Week 3 The Request: Form Enter your name and address. Then click the Send button to send the data to the server. Name Address Servlet processes a request from a web page. It responds to the request by echoing back the name and address that was sent in.

Java Servlets Review: Java Servlets 3COMP9321, 15s2, Week 3 The Servlet: package echo; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Servlet extends HttpServlet { doGet protected void doGet (HttpServletRequest request, HttpServletResponse response) {try{ response.setContentType ("text/html"); PrintWriter out = response.getWriter (); String name = request.getParameter ("name"); String = request.getParameter (" "); out.println (" "); out.println (" Hello. "); out.println (" " + name+ " "); out.println (" Your address is " + + " "); out.println (" "); }catch (IOException e) {System.out.println ("Servlet Exception");} }

Java Servlets Review: Java Servlets 4COMP9321, 15s2, Week 3 Deployment Descriptor : web.xml Servlet echo. Servlet Servlet /servlet/echo. Servlet

JavaServer Pages (JSP) Technology 5COMP9321, 15s2, Week 3 JavaServer Pages (JSP) technology allows you to easily create web content that has both static and dynamic components. JSP technology makes available all the dynamic capabilities of Java Servlet technology; but provides a more natural approach to creating static content. JSP is similar to PHP, but it uses the Java programming language. To deploy and run JavaServer Pages, a compatible web server with a servlet container, such as Apache Tomcat, is required.

Main Features of JSP technology 6COMP9321, 15s2, Week 3 A language for developing JSP pages, which are text-based documents that describe how to process a request and construct a response; An Expression Language (EL) for accessing server-side objects; Mechanisms for defining extensions to the JSP language;

JSP Page 7COMP9321, 15s2, Week 3 A JSP page is a text document that contains two types of text: static data: o which can be expressed in any text-based format (such as HTML, SVG, WML, and XML); JSP elements: o which construct dynamic content; o The recommended file extension for the source file of a JSP page is.jsp. o The recommended extension for the source file of a fragment of a JSP page is.jspf.

JSP Page 8COMP9321, 15s2, Week 3 Kinds of tags: is used for expressions. e.g. is used for declarations. e.g. is used for straight Java code. e.g. 5) { … %> is used to include another file such as an HTML file or a package such as java.sql.*. e.g.

JSP Example 9COMP9321, 15s2, Week 3 The Request: Enter your name and address: Name

JSP Example 10COMP9321, 15s2, Week 3 JSP File: <jsp:setProperty name="hello" property="name" value=' ‘ /> <jsp:setProperty name="hello" property=" " value=‘ ‘ /> <% name = hello.getName(); = hello.get (); out.println (" Hello, your name is " + name); out.println (" and your address is " + + ". "); %>

JSP Example 11COMP9321, 15s2, Week 3 JSP File: <jsp:setProperty name="hello" property="name" value=' ‘ /> <jsp:setProperty name="hello" property=" " value=‘ ‘ /> <% name = hello.getName(); = hello.get (); out.println (" Hello, your name is " + name); out.println (" and your address is " + + ". "); %> page directive page directive. sets the content type returned by the page. page directive page directive. sets the content type returned by the page.

JSP Example 12COMP9321, 15s2, Week 3 JSP File: <jsp:setProperty name="hello" property="name" value=' ‘ /> <jsp:setProperty name="hello" property=" " value=‘ ‘ /> <% name = hello.getName(); = hello.get (); out.println (" Hello, your name is " + name); out.println (" and your address is " + + ". "); %> Tag library directives. Tag library directives. import custom tag libraries. JavaServer Pages Standard Tag Library (JSTL): JSTL extends the JSP specification by adding a tag library of JSP tags for common tasks, such as conditional execution, loops, and database access. Tag library directives. Tag library directives. import custom tag libraries. JavaServer Pages Standard Tag Library (JSTL): JSTL extends the JSP specification by adding a tag library of JSP tags for common tasks, such as conditional execution, loops, and database access.

JSP Example 13COMP9321, 15s2, Week 3 JSP File: <jsp:setProperty name="hello" property="name" value=' ‘ /> <jsp:setProperty name="hello" property=" " value=‘ ‘ /> <% name = hello.getName(); = hello.get (); out.println (" Hello, your name is " + name); out.println (" and your address is " + + ". "); %> is a standard element that creates an object containing a collection of locales and initializes an identifier that points to that object. is used to locate or instantiate a bean class. JavaBeans are classes that encapsulate many objects into a single object (the bean). Each JavaServer page can be associated with a Java bean. is a standard element that creates an object containing a collection of locales and initializes an identifier that points to that object. is used to locate or instantiate a bean class. JavaBeans are classes that encapsulate many objects into a single object (the bean). Each JavaServer page can be associated with a Java bean.

JSP Example 14COMP9321, 15s2, Week 3 JSP File: <jsp:setProperty name="hello" property="name" value=' ‘ /> <jsp:setProperty name="hello" property=" " value=‘ ‘ /> <% name = hello.getName(); = hello.get (); out.println (" Hello, your name is " + name); out.println (" and your address is " + + ". "); %> is a standard element that sets the value of an object property. is a standard element that sets the value of an object property.

JSP Example 15COMP9321, 15s2, Week 3 JSP File: <jsp:setProperty name="hello" property="name" value=' ‘ /> <jsp:setProperty name="hello" property=" " value=‘ ‘ /> <% name = hello.getName(); = hello.get (); out.println (" Hello, your name is " + name); out.println (" and your address is " + + ". "); %> Some reserved words (JSP Objects): request – an instance of HttpServletRequest. response – an instance of HttpServletResponse. out – a PrintWriter object for the response. session – the HttpSession object associated with the session. application – an instance of ServletContext Some reserved words (JSP Objects): request – an instance of HttpServletRequest. response – an instance of HttpServletResponse. out – a PrintWriter object for the response. session – the HttpSession object associated with the session. application – an instance of ServletContext

JSP Example 16COMP9321, 15s2, Week 3 The Bean: public class HelloBean { private String name = ""; private String = ""; public String getName() {return name;} public String get () {return ;} public void setName (String n) {name = n;} public void set (String e) { = e;} } // HelloBean Each Java server page is associated with a Java bean. These are Java programs and reside on the server. o The constructor has no parameters o All variables have accessor (get) and mutator (set) methods.

JSP 17COMP9321, 15s2, Week 3

JSP 18COMP9321, 15s2, Week 3

JSP 19COMP9321, 15s2, Week 3

Let us Revisit the WelcomeServlet 20COMP9321, 15s2, Week 3

Here is equivalent in JSP (welcome.jsp) 21COMP9321, 15s2, Week 3

JSP Basics 22COMP9321, 15s2, Week 3 JSP Page JSP Elements Template Text (HTML bits…) Scripting Elements Directive Elements Action Elements Traditional Modern EL Scripting ${…} Scriptlet Expression Declaration Comments Page Include Taglib custom Standard

JSP Basics 23COMP9321, 15s2, Week 3 JSP Page JSP Elements Template Text (HTML bits…) Scripting Elements DirectiveElements Action Elements Traditional Modern EL Scripting ${…} Scriptlet Expression Declaration Comments Page Include Taglib custom Standard

JSP Elements: JSP directives 24COMP9321, 15s2, Week 3

JSP Basics 25COMP9321, 15s2, Week 3 JSP Page JSP Elements Template Text (HTML bits…) ScriptingElements Directive Elements Action Elements Traditional Modern EL Scripting ${…} Scriptlet Expression Declaration Comments Page Include Taglib custom Standard

JSP Elements: JSP Scripting (expression) 26COMP9321, 15s2, Week 3

JSP Elements: Using the implicit objects 27COMP9321, 15s2, Week 3  request: the HttpServletRequest object  response: the HttpServletResponse object  session: the HttpSession object associated with the request  out:  out: the Writer object  config:  config: the ServletCong object  application:  application: the ServletContext objectExample: JSP expressions Current time is: Server Info: Servlet Init Info: This Session ID: The value of TestParam is:

JSP Elements: JSP Scripting (scriptlet) 28COMP9321, 15s2, Week 3 JSP scriptlet, are inserted verbatim into the translated servlet code. The scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within a scriptlet, you can do any of the following: Declare variables or methods to use later in the JSP page. Write expressions valid in the page scripting language. Use any of the implicit objects or any object declared with a element. Write any other statement valid in the scripting language used in the JSP page. Remember that JSP expressions contain `(string) values', but JSP scriptlets contain `Java statements'.

JSP Elements: JSP Scripting (scriptlet) 29COMP9321, 15s2, Week 3 Example: Hello! The time is: Your machine's address is: " ); out.println( request.getRemoteHost()); %>

JSP Elements: JSP Scripting (scriptlet) 30COMP9321, 15s2, Week 3 The following three examples, generate the same output …

JSP Elements: JSP Scripting (scriptlet) 31COMP9321, 15s2, Week 3 Example, setting the background of a page (CoreServlet p.334)

JSP Elements: JSP Scripting (scriptlet) 32COMP9321, 15s2, Week 3 You can also use the scriptlet to conditionally generate HTML.

JSP Elements: JSP Scripting (comment) 33COMP9321, 15s2, Week 3

Attributes in a JSP 34COMP9321, 15s2, Week 3 (HeadFirst) p.309 Recall from last week. Request attributes and RequestDispatcher: We use request attributes when we want some other component of the application take over all or part of your request….

JSP Basics 35COMP9321, 15s2, Week 3 JSP Page JSP Elements Template Text (HTML bits…) Scripting Elements Directive Elements ActionElements Traditional Modern EL Scripting ${…} Scriptlet Expression Declaration Comments Page Include Taglib custom Standard

JSP Elements: JSP Actions 36COMP9321, 15s2, Week 3 (HeadFirst) p.309

JSP Elements: JSP Actions (include) 37COMP9321, 15s2, Week 3

jsp:include vs. include directive 38COMP9321, 15s2, Week 3 (CoreServlet p.380)

JSP Elements: JSP Actions (forward) 39COMP9321, 15s2, Week 3

JSP Elements: JSP Actions (useBean) 40COMP9321, 15s2, Week 3

JSP Elements: JSP Actions (useBean) 41COMP9321, 15s2, Week 3

JSP Elements: JSP Actions (useBean) 42COMP9321, 15s2, Week 3

JSP Elements: JSP Actions (useBean) 43COMP9321, 15s2, Week 3 Sharing Beans: using scope attribute

JSP Elements: JSP Actions (useBean) 44COMP9321, 15s2, Week 3 Sharing Beans: using scope attribute

JSP Basics 45COMP9321, 15s2, Week 3 JSP Page JSP Elements Template Text (HTML bits…) Scripting Elements Directive Elements Action Elements Traditional Modern EL Scripting ${…} Scriptlet Expression Declaration Comments Page Include Taglib custom Standard

Expression Language (EL) in JSP 46COMP9321, 15s2, Week 3

Expression Language (EL) in JSP 47COMP9321, 15s2, Week 3

Expression Language (EL) in JSP 48COMP9321, 15s2, Week 3 Towards Script-less JSP

Expression Language (EL) in JSP 49COMP9321, 15s2, Week 3 (HeadFIrst) p.367

Expression Language (EL) in JSP 50COMP9321, 15s2, Week 3

EL Basics: Accessing Scoped Variables 51COMP9321, 15s2, Week 3

EL Basics: Accessing Scoped Variables 52COMP9321, 15s2, Week 3

EL Basics: Using dot vs. Using [ ] operator 53COMP9321, 15s2, Week 3

EL Basics: Using dot vs. Using [ ] operator 54COMP9321, 15s2, Week 3

EL Basics: Using dot vs. Using [ ] operator 55COMP9321, 15s2, Week 3

EL Basics: Using dot vs. Using [ ] operator 56COMP9321, 15s2, Week 3

EL Basics: Using dot vs. Using [ ] operator 57COMP9321, 15s2, Week 3

EL Basics: Using dot vs. Using [ ] operator 58COMP9321, 15s2, Week 3

EL Basics: EL Implicit Objects 59COMP9321, 15s2, Week 3

EL Basics: EL Implicit Objects 60COMP9321, 15s2, Week 3

EL Basics: EL Implicit Objects 61COMP9321, 15s2, Week 3

EL Basics: EL Operators 62COMP9321, 15s2, Week 3

JSP Standard Tag Library (JSTL) 63COMP9321, 15s2, Week 3

JSP Standard Tag Library (JSTL) 64COMP9321, 15s2, Week 3

JSP Standard Tag Library (JSTL) 65COMP9321, 15s2, Week 3

JSP Standard Tag Library (JSTL) 66COMP9321, 15s2, Week 3

JSP Standard Tag Library (JSTL) 67COMP9321, 15s2, Week 3

JSTL Basics: Looping collections 68COMP9321, 15s2, Week 3

JSTL Basics: Looping collections 69COMP9321, 15s2, Week 3

JSTL Basics: Looping collections 70COMP9321, 15s2, Week 3

JSTL Basics: Conditional output 71COMP9321, 15s2, Week 3

JSTL Basics: Conditional output 72COMP9321, 15s2, Week

JSTL Basics: Using JSTL Basics: Using 73COMP9321, 15s2, Week 3

JSTL Basics: Using JSTL Basics: Using 74COMP9321, 15s2, Week 3

JSTL Basics: Working with URL 75COMP9321, 15s2, Week 3

Other things available in JSTL 76COMP9321, 15s2, Week 3

JSP Basics 77COMP9321, 15s2, Week 3 JSP Page JSP Elements Template Text (HTML bits…) Scripting Elements Directive Elements Action Elements Traditional Modern EL Scripting ${…} Scriptlet Expression Declaration Comments Page Include Taglib custom Standard

JSP Custom Tags 78COMP9321, 15s2, Week 3

JSP Custom Tags 79COMP9321, 15s2, Week 3

JSP Custom Tags 80COMP9321, 15s2, Week 3

JSP Custom Tags 81COMP9321, 15s2, Week 3

JSP Custom Tags 82COMP9321, 15s2, Week 3

JSP Custom Tags 83COMP9321, 15s2, Week 3

JSP 84COMP9321, 15s2, Week 3

85COMP9321, 15s2, Week 3