COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web...

81
COMP9321 Web Application Engineering Semester 2, 2017 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1 COMP9321, 17s2, Week 3 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2465

Transcript of COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web...

Page 1: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

COMP9321 Web Application EngineeringSemester 2, 2017

Dr. Amin BeheshtiService Oriented Computing Group, CSE, UNSW Australia

Week 3

1COMP9321, 17s2, Week 3

http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2465

Page 2: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Review: Static vs. Dynamic Web Page

2COMP9321, 17s2, Week 3

A static web page is delivered to the user exactly as stored, in contrast to dynamic web pages which are generated by a web application, and on demand!

web page whose construction is controlled by an application server processing server-side scripts.

software framework that provides both facilities to create web applications and a server environment to run them.

is-a

is-a

Java application servers

e.g.

It's core set of API and features are defined by Java EE.

The Web modules include Java Servlets and JavaServer Pages (JSP).

http://docs.oracle.com/javaee/6/tutorial/doc/

Page 3: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Review: Java Servlets

3COMP9321, 17s2, Week 3

http://java.sun.com/products/servlet/index.jsphttp://docs.oracle.com/javaee/6/tutorial/doc/bnafd.html

Page 4: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JavaServer Pages (JSP) Technology

4COMP9321, 17s2, Week 3

Page 5: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JavaServer Pages (JSP) Technology

5COMP9321, 17s2, 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 ofJava Servlet technology; but provides a more natural approachto creating static content.

• JSP is similar to PHP, but it uses the Java programminglanguage.

• To deploy and run JavaServer Pages, a compatible web serverwith a servlet container, such as Apache Tomcat, is required.

Page 6: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Main Features of JSP technology

6COMP9321, 17s2, Week 3

• A language for developing JSP pages, which are text-baseddocuments that describe how to process a request andconstruct a response;

• An Expression Language (EL) for accessing server-sideobjects;

• Mechanisms for defining extensions to the JSP language;

Page 7: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Page

7COMP9321, 17s2, 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.

Encapsulates a portion of JSP code in an object that can be invoked as many times as needed.

Page 8: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Page

8COMP9321, 17s2, Week 3

Kinds of tags:• <%= … %> is used for expressions.

• e.g. <%= request.getParameter ("email") %>

• <%! … %> is used for declarations.• e.g. <%! String name, email; %>

• <% … %> is used for straight Java code.• e.g. <% if (x > 5) { … %>

• <%@ … %> is used to include another file (e.g.HTML file) or a package (e.g. java.sql.*).• e.g. <%@ page contentType="text/html; charset=UTF-8" %>• e.g. <%@ taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c" %>

Page 9: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

9COMP9321, 17s2, Week 3

The Request:

<html><body><h3>Enter your name and email address: </h3><form method="get" action="hello.jsp">

<p><input type="text" name="name" value="" size="20"/> Name </p><p><input type="text" name="email" value="" size="20"/> Email </p><p><input type="submit" name="Send" value="Send"/> </p>

</form></body>

</html>

Page 10: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

10COMP9321, 17s2, Week 3

JSP File: hello.jsp

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

Page 11: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

11COMP9321, 17s2, Week 3

JSP File:

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

<%@page ... %>• page directive.• sets the content type returned by the page.

Page 12: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

12COMP9321, 17s2, Week 3

JSP File:

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

<%@taglib ... %>• 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.

Page 13: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

13COMP9321, 17s2, Week 3

JSP File:

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

<jsp:useBean …>• 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.

• Google(“what is a bean class?”)

Page 14: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

14COMP9321, 17s2, Week 3

JSP File:

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

Page 15: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

15COMP9321, 17s2, Week 3

JSP File:

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

<jsp:setProperty …>• is a standard element that sets the value of an object property.

Page 16: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

16COMP9321, 17s2, Week 3

JSP File:

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

Page 17: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

17COMP9321, 17s2, Week 3

JSP File:

<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core " …%><html><body>

<%! String name, email; %><jsp:useBean id="hello" scope="session" class="greetings.HelloBean" /><jsp:setProperty name="hello" property="name"

value='<%= request.getParameter ("name") %>‘ /><jsp:setProperty name="hello" property="email"

value=‘<%= request.getParameter ("email") %>‘ /><%

name = hello.getName();email = hello.getEmail();out.println ("<h3>Hello, your name is " + name);out.println (" and your email address is " + email + ".</h3>");

%></body></html>

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

Page 18: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Example

18COMP9321, 17s2, Week 3

The Bean:

public class HelloBean{

private String name = "";private String email = "";

public String getName() {return name;}public String getEmail() {return email;}

public void setName (String n) {name = n;}public void setEmail (String e) {email = e;}

} // HelloBean

• Each Java server page is associated with a Java bean.• These are Java programs and reside on the server.

o All variables have accessor (get) and mutator (set) methods.

Page 19: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP

19COMP9321, 17s2, Week 3

Page 20: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Let us Revisit the WelcomeServlet

20COMP9321, 17s2, Week 3

Page 21: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Here is equivalent in JSP (welcome.jsp)

21COMP9321, 17s2, Week 3

Page 22: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Basics

22COMP9321, 17s2, Week 3

JSP Page

JSP Elements

Template Text (HTML bits…)

ScriptingElements

DirectiveElements

ActionElements

Traditional

Modern EL Scripting${…}

ScriptletExpressionDeclarationComments

PageIncludeTaglib

custom

Standard

<abc:mytag>

<jsp:useBean><jsp:getProperty><jsp:setProperty><jsp:include><jsp:forward><jsp:param>

Page 23: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Basics

23COMP9321, 17s2, Week 3

JSP Page

JSP Elements

Template Text (HTML bits…)

ScriptingElements

DirectiveElements

ActionElements

Traditional

Modern EL Scripting${…}

ScriptletExpressionDeclarationComments

PageIncludeTaglib

custom

Standard

<abc:mytag>

<jsp:useBean><jsp:getProperty><jsp:setProperty><jsp:include><jsp:forward><jsp:param>

Page 24: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP directives

24COMP9321, 17s2, Week 3

Page 25: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP directives

25COMP9321, 17s2, Week 3

http://www.tutorialspoint.com/jsp/taglib_directive.htm

<%@ taglib uri="http://www.example.com/custlib" prefix="mytag" %><html><body><mytag:hello/></body></html>

Page 26: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Basics

26COMP9321, 17s2, Week 3

JSP Page

JSP Elements

Template Text (HTML bits…)

ScriptingElements

DirectiveElements

ActionElements

Traditional

Modern EL Scripting${…}

ScriptletExpressionDeclarationComments

PageIncludeTaglib

custom

Standard

<abc:mytag>

<jsp:useBean><jsp:getProperty><jsp:setProperty><jsp:include><jsp:forward><jsp:param>

Page 27: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Scripting (expression)

27COMP9321, 17s2, Week 3

Page 28: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: Using the implicit objects

28COMP9321, 17s2, Week 3

request: the HttpServletRequest object response: the HttpServletResponse object session: the HttpSession object associated with the request out: the Writer object config: the ServletCong object application: the ServletContext object

Example:<html><body>

<h2>JSP expressions</h2><ul>

<li>Current time is: <%= new java.util.Date() %><li>Server Info: <%= application.getServerInfo() %> <li>Servlet Init Info: <%= config.getInitParameter("WebMaster") %><li>This Session ID: <%= session.getId() %><li>The value of <code>TestParam</code> is:<%= request.getParameter("TestParam") %>

</ul></body></html>

Page 29: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Scripting (scriptlet)

29COMP9321, 17s2, 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 <jsp:useBean> 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'.

Page 30: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Scripting (scriptlet)

30COMP9321, 17s2, Week 3

Example:

<HTML><BODY>

<%// This scriptlet declares and initializes "date"java.util.Date date = new java.util.Date();

%>Hello! The time is:<%

out.println( date );out.println( "<BR>Your machine's address is: " );out.println( request.getRemoteHost());

%></BODY></HTML>

Page 31: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Scripting (scriptlet)

31COMP9321, 17s2, Week 3

The following three examples, generate the same output …

Page 32: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Scripting (scriptlet)

32COMP9321, 17s2, Week 3

Example, setting the background of a page

(CoreServlet p.334)

Page 33: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Scripting (scriptlet)

33COMP9321, 17s2, Week 3

You can also use the scriptlet to conditionally generate HTML.

Page 34: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Scripting (comment)

34COMP9321, 17s2, Week 3

Page 35: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Attributes in a JSP

35COMP9321, 17s2, 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….

Page 36: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Basics

36COMP9321, 17s2, Week 3

JSP Page

JSP Elements

Template Text (HTML bits…)

ScriptingElements

DirectiveElements

ActionElements

Traditional

Modern EL Scripting${…}

ScriptletExpressionDeclarationComments

PageIncludeTaglib

custom

Standard

<abc:mytag>

<jsp:useBean><jsp:getProperty><jsp:setProperty><jsp:include><jsp:forward><jsp:param>

Page 37: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions

37COMP9321, 17s2, Week 3

(HeadFirst) p.309

Page 38: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions (include)

38COMP9321, 17s2, Week 3

Page 39: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

jsp:include vs. include directive

39COMP9321, 17s2, Week 3

(CoreServlet p.380)

Page 40: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions (forward)

40COMP9321, 17s2, Week 3

Page 41: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions (useBean)

41COMP9321, 17s2, Week 3

Page 42: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions (useBean)

42COMP9321, 17s2, Week 3

Page 43: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions (useBean)

43COMP9321, 17s2, Week 3

Page 44: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions (useBean)

44COMP9321, 17s2, Week 3

Sharing Beans: using scope attribute

Page 45: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Elements: JSP Actions (useBean)

45COMP9321, 17s2, Week 3

Sharing Beans: using scope attribute

Page 46: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Basics

46COMP9321, 17s2, Week 3

JSP Page

JSP Elements

Template Text (HTML bits…)

ScriptingElements

DirectiveElements

ActionElements

Traditional

Modern EL Scripting${…}

ScriptletExpressionDeclarationComments

PageIncludeTaglib

custom

Standard

<abc:mytag>

<jsp:useBean><jsp:getProperty><jsp:setProperty><jsp:include><jsp:forward><jsp:param>

Page 47: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Expression Language (EL) in JSP

47COMP9321, 17s2, Week 3

Page 48: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Expression Language (EL) in JSP

48COMP9321, 17s2, Week 3

Page 49: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Expression Language (EL) in JSP

49COMP9321, 17s2, Week 3

Towards Script-less JSP

Page 50: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Expression Language (EL) in JSP

50COMP9321, 17s2, Week 3

(HeadFIrst) p.367

Page 51: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Expression Language (EL) in JSP

51COMP9321, 17s2, Week 3

Page 52: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Accessing Scoped Variables

52COMP9321, 17s2, Week 3

Page 53: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Accessing Scoped Variables

53COMP9321, 17s2, Week 3

Page 54: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Using dot vs. Using [ ] operator

54COMP9321, 17s2, Week 3

Page 55: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Using dot vs. Using [ ] operator

55COMP9321, 17s2, Week 3

Page 56: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Using dot vs. Using [ ] operator

56COMP9321, 17s2, Week 3

Page 57: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Using dot vs. Using [ ] operator

57COMP9321, 17s2, Week 3

Page 58: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Using dot vs. Using [ ] operator

58COMP9321, 17s2, Week 3

Page 59: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: Using dot vs. Using [ ] operator

59COMP9321, 17s2, Week 3

Page 60: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: EL Implicit Objects

60COMP9321, 17s2, Week 3

Page 61: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: EL Implicit Objects

61COMP9321, 17s2, Week 3

Page 62: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: EL Implicit Objects

62COMP9321, 17s2, Week 3

Page 63: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

EL Basics: EL Operators

63COMP9321, 17s2, Week 3

Page 64: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Assignment 1

64COMP9321, 17s2, Week 3

Page 65: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Appendix

65COMP9321, 17s2, Week 3

JSP Standard Tag Library (JSTL)

AND

JSP Custom Tags

Page 66: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Standard Tag Library (JSTL)

66COMP9321, 17s2, Week 3

Page 67: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Standard Tag Library (JSTL)

67COMP9321, 17s2, Week 3

Page 68: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Standard Tag Library (JSTL)

68COMP9321, 17s2, Week 3

Page 69: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Standard Tag Library (JSTL)

69COMP9321, 17s2, Week 3

Page 70: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Standard Tag Library (JSTL)

70COMP9321, 17s2, Week 3

Page 71: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSTL Basics: Looping collections

71COMP9321, 17s2, Week 3

Page 72: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSTL Basics: Looping collections

72COMP9321, 17s2, Week 3

Page 73: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSTL Basics: Looping collections

73COMP9321, 17s2, Week 3

Page 74: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSTL Basics: Conditional output

74COMP9321, 17s2, Week 3

Page 75: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSTL Basics: Conditional output

75COMP9321, 17s2, Week 3

2- https://www.ibm.com/developerworks/library/j-jstl0318/

Page 76: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSTL Basics: Using <c:set>

76COMP9321, 17s2, Week 3

Page 77: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

Other things available in JSTL

77COMP9321, 17s2, Week 3

Page 78: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Basics

78COMP9321, 17s2, Week 3

JSP Page

JSP Elements

Template Text (HTML bits…)

ScriptingElements

DirectiveElements

ActionElements

Traditional

Modern EL Scripting${…}

ScriptletExpressionDeclarationComments

PageIncludeTaglib

custom

Standard

<abc:mytag>

<jsp:useBean><jsp:getProperty><jsp:setProperty><jsp:include><jsp:forward><jsp:param>

Page 79: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Custom Tags

79COMP9321, 17s2, Week 3

Page 80: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

JSP Custom Tags

80COMP9321, 17s2, Week 3

http://www.tutorialspoint.com/jsp/jsp_custom_tags.htm

http://docs.oracle.com/javaee/5/tutorial/doc/bnalj.html

Example:

More Details:

Page 81: COMP9321 Web Application Engineeringcs9321/17s2/lectures/lec03/Lec-03.pdf · COMP9321 Web Application Engineering Semester 2, 2017 Dr.Amin Beheshti Service Oriented Computing Group,

81COMP9321, 17s2, Week 3