06/09/14 10. A (very) short intro to JSP 10. A (very) short intro - - PDF document

06 09 14
SMART_READER_LITE
LIVE PREVIEW

06/09/14 10. A (very) short intro to JSP 10. A (very) short intro - - PDF document

06/09/14 10. A (very) short intro to JSP 10. A (very) short intro to JSP Dynamic web pages Dynamic web pages Internet HTTP Request Web browser Web browser Advanced CS Intro


slide-1
SLIDE 1

06/09/14 1

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser Internet HTTP Request

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser Internet HTTP Request

W

Web server

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser Internet HTTP Request

W

Web server

Ser

Server

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser Internet HTTP Request

W

Web server

Ser JSP

Server

JSP Engine

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser Internet HTTP Request

W

Web server

Ser JSP S

Server

JSP Engine Servlet Engine

slide-2
SLIDE 2

06/09/14 2

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser Internet HTTP Request

W

Web server

Ser JSP S

Server

JSP Engine Servlet Engine

HTTP Response Internet

  • 10. A (very) short intro to JSP

Dynamic web pages

Advanced CS Intro J. Denzinger

Web browser Internet HTTP Request

W

Web server

Ser JSP S

Server

JSP Engine Servlet Engine

HTTP Response Internet Tomcat

10.1 HTML HyperText Markup Language Method for putting structured information (about formatting of text) into a text file

 Based on tags  Tags enclose information that is displayed

according to the semantics of the tag

 Tags can be nested  Tags can have parameters

Advanced CS Intro J. Denzinger

10.2 JSP Java Server Pages

 One way to create dynamic web pages  Also tag-based  JSP engine allows to combine html tags with

Java code (including import statements) to produce a Java servlet

 Java servlet is then executed to create an html

page as result of http request

Advanced CS Intro J. Denzinger

JSP elements

 Scripting: manipulate Java objects by invoking

their methods, also can catch exceptions

 Directive: messages to Tomcat  Action: encapsulate activities that Tomcat

performs when handling an http request

 Implicit objects: objects created by Tomcat that

can be used in JSPs

Advanced CS Intro J. Denzinger

Scripting elements

 Consists of code delimited by particular

character sequences

 Code is a Java fragment  <% … %> for scriplets (block of Java code)  <%- … %> for expressions (inserts result of

expression into page)

 <%! … %> for declarations (creates an

instance variable shared by all requests for the page)

Advanced CS Intro J. Denzinger

slide-3
SLIDE 3

06/09/14 3

Directive elements

 General syntax:

<%@directive-name attr1=“value1” [attr2=“value2”…] %>

 page directive defines page-dependent

properties and allows setting their values

 include directive allows to insert unprocessed

text file

 taglib directive allows to include tag libraries

Advanced CS Intro J. Denzinger

Action elements

 General syntax:

<jsp:action-name attribute-list> <jsp:subaction-name subaction-attribute-list/> </jsp:action-name>

 Actions are executed every time an http-request

is made for the page containing it

 A user can also define his/her own actions (and

associated tags) (which need to be implemented via defining a Java class and require a tag library descriptor realized as an XML file)

Advanced CS Intro J. Denzinger

  • ptional

Actions (selection)

 forward: transfers http-request to another page  include: include another page, process it, then

continue processing of current page

 param: subaction that allows to set parameters

for pages in forward/include actions

 element, attribute, body: used to define XML

elements

Advanced CS Intro J. Denzinger

Implicit objects (selection)

 Objects (with associated methods) created by

Tomcat within one of four scopes: application, session, request or page

 application provides access to resources shared

within the whole web application

 config is used to pass information to servlets  out is used as output  request gives access to the HTTP request sent

by the browser

Advanced CS Intro J. Denzinger

Implicit objects (selection) (cont.)

 response gives access to the HTTP response

that will be sent to the browser

 session allows to store information about a

user session

Advanced CS Intro J. Denzinger

10.3 Sources Giulio Zambon: Beginning JSP, JSF and Tomcat Apress, 2012

Advanced CS Intro J. Denzinger