06 09 14
play

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


  1. 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 J. Denzinger Advanced CS Intro J. Denzinger 10. A (very) short intro to JSP 10. A (very) short intro to JSP Dynamic web pages Dynamic web pages Internet Internet HTTP Request HTTP Request Web browser Web browser Server Ser W W Web server Web server Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger 10. A (very) short intro to JSP 10. A (very) short intro to JSP Dynamic web pages Dynamic web pages Internet Internet HTTP Request HTTP Request Web browser Web browser JSP JSP JSP JSP Engine Engine Server Ser Server Ser W W Servlet S Engine Web server Web server Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger 1

  2. 06/09/14 10. A (very) short intro to JSP 10. A (very) short intro to JSP Dynamic web pages Dynamic web pages Internet Internet HTTP Request HTTP Request Web browser Web browser Tomcat HTTP Response HTTP Response JSP JSP JSP JSP Engine Engine Internet Internet Server Ser Server Ser W W Servlet Servlet S S Engine Engine Web server Web server Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger 10.1 HTML 10.2 JSP HyperText Markup Language Java Server Pages Method for putting structured information  One way to create dynamic web pages (about formatting of text) into a text file  Also tag-based  Based on tags  JSP engine allows to combine html tags with  Tags enclose information that is displayed Java code (including import statements) to according to the semantics of the tag produce a Java servlet  Tags can be nested  Java servlet is then executed to create an html page as result of http request  Tags can have parameters Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger JSP elements Scripting elements  Scripting: manipulate Java objects by invoking  Consists of code delimited by particular their methods, also can catch exceptions character sequences  Directive: messages to Tomcat  Code is a Java fragment  Action: encapsulate activities that Tomcat  <% … %> for scriplets (block of Java code) performs when handling an http request  <%- … %> for expressions (inserts result of  Implicit objects: objects created by Tomcat that expression into page) can be used in JSPs  <%! … %> for declarations (creates an instance variable shared by all requests for the page) Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger 2

  3. 06/09/14 Directive elements Action elements  General syntax:  General syntax: optional <jsp:action-name attribute-list> <%@directive-name attr 1 =“value 1 ” <jsp:subaction-name subaction-attribute-list/> [attr 2 =“value 2 ”…] %> </jsp:action-name>  page directive defines page-dependent  Actions are executed every time an http-request properties and allows setting their values is made for the page containing it  include directive allows to insert unprocessed  A user can also define his/her own actions (and associated tags) text file (which need to be implemented via defining a Java  taglib directive allows to include tag libraries class and require a tag library descriptor realized as an XML file) Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger Actions (selection) Implicit objects (selection)  forward : transfers http-request to another page  Objects (with associated methods) created by Tomcat within one of four scopes: application,  include : include another page, process it, then session, request or page continue processing of current page  application provides access to resources shared  param : subaction that allows to set parameters within the whole web application for pages in forward / include actions  config is used to pass information to servlets  element , attribute , body : used to define XML elements  out is used as output  request gives access to the HTTP request sent by the browser Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger Implicit objects (selection) (cont.) 10.3 Sources  response gives access to the HTTP response Giulio Zambon: that will be sent to the browser Beginning JSP, JSF and Tomcat  session allows to store information about a Apress, 2012 user session Advanced CS Intro J. Denzinger Advanced CS Intro J. Denzinger 3

Recommend


More recommend