at-m42:lecture13
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
at-m42:lecture13 [2009/04/21 17:22] – eechris | at-m42:lecture13 [2011/01/14 12:45] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
~~SLIDESHOW~~ | ~~SLIDESHOW~~ | ||
- | ====== Presentation | + | ====== Presentation-tier Services ====== |
* Server services is the largest market sector in Java world((Mobile may well become more important, certainly in terms of installed systems, if not in terms of monetary value, we shall see)). | * Server services is the largest market sector in Java world((Mobile may well become more important, certainly in terms of installed systems, if not in terms of monetary value, we shall see)). | ||
Line 19: | Line 19: | ||
* Despite best efforts of some, server is not a single source platform (e.g. WinTel): much more heterogeneous than the typical client (Desktop). | * Despite best efforts of some, server is not a single source platform (e.g. WinTel): much more heterogeneous than the typical client (Desktop). | ||
* The Java platform offers platform-independent server environment with developing support that allow links to “legacy” applications. | * The Java platform offers platform-independent server environment with developing support that allow links to “legacy” applications. | ||
- | * Possibly most important server application is ability to link to an SQL database: this is provided in Java by the JDBC package (see [[lecture15|Integration Tier Services]]). | + | * Possibly most important server application is ability to link to an SQL database: this is provided in Java by the JDBC package (see [[lecture14|Integration Tier Services]]). |
* Next most important is web services providing (browser based) thin-client applications for e-commerce, in institutions via the intranet and to the general public via the Internet. | * Next most important is web services providing (browser based) thin-client applications for e-commerce, in institutions via the intranet and to the general public via the Internet. | ||
Line 37: | Line 37: | ||
* [[#Web Designers Want Templates Not Code!]] | * [[#Web Designers Want Templates Not Code!]] | ||
* [[#Groovy Server Pages]] | * [[#Groovy Server Pages]] | ||
- | * [[# | + | * [[#Architectural Issues: Patterns|Architectural issues to be aware of!]] |
Line 318: | Line 318: | ||
* [[#Web Designers Want Templates Not Code!]] | * [[#Web Designers Want Templates Not Code!]] | ||
* [[#Groovy Server Pages]] | * [[#Groovy Server Pages]] | ||
- | * [[# | + | * [[#Architectural Issues: Patterns|Architectural issues to be aware of!]] |
===== Java Server Pages ===== | ===== Java Server Pages ===== | ||
Line 440: | Line 440: | ||
</ | </ | ||
- | Contents | + | ===== Lecture |
- | Servlets | + | |
- | Java Server Pages (JSP) | + | |
- | Web Designers Want Templates Not Code! | + | |
- | Architectural issues to be aware of! | + | |
- | Templates Not Code! | + | * [[#Servlets and Groovlets]] |
- | You’ll have noticed that the Servlet/JSP programming model is far from ideal | + | * [[#Java Server Pages]] |
- | Servlets: HTML embedded in print statements | + | * **[[#Web Designers Want Templates Not Code!]]** |
- | JSP: Java code embedded in HTML | + | * [[#Groovy Server Pages]] |
- | Suits no-one! | + | * [[# |
- | Web designers work in HTML, not Java! | + | |
- | Java programmers work in code, not HTML! | + | |
- | Mixing them up is error prone and does not separate concerns | + | |
- | Recognising this, common pattern is to put code into helper applications and embed a simpler “templating” language into the HTML. | + | |
- | Pattern Template View – renders information into HTML by embedding markers in an HTML page. | + | |
- | Examples of Template View implementations | + | |
- | Not for discussion here … to be studied as part of your seminar project. | + | |
- | Java standard is to use “custom tags” that talk to Java classes. | + | |
- | Tags look like XML tags (with namespaces) in (X)HTML pages | + | |
- | JSTL – Java Standard Tag Library provides access to beans and provides simple programming logic tags. | + | |
- | Can eliminate <% … %> from JSP code! | + | |
- | Several open source alternatives: | + | |
- | Best regarded seems to be Velocity (another apache project) | + | |
- | Very simple template language embedded in HTML | + | |
- | Parsed and replaced by computational results (by a special Servlet) at access time. | + | |
- | Transparent to web developers who just see HTML pages. | + | |
- | Contents | + | |
- | Servlets | + | |
- | Java Server Pages (JSP) | + | |
- | Web Designers Want Templates Not Code! | + | |
- | Architectural issues to be aware of! | + | |
- | Architectural Issues: Patterns | + | ===== Templates Not Code! ===== |
- | Web container gets its requests from a web client in HTTP and returns HTML views of the application’s business objects. | + | * You’ll have noticed that the Servlet/JSP programming model is far from ideal |
- | Business objects are Java objects in the business tier. | + | * Suits no-one! |
- | Web Tier communicates with the Business Tier either using RMI or by directly via Java objects. | + | * Web designers work in HTML, not Java! |
- | Many presentation layer patterns are designed to simplify (or at least manage) the difficulties inherent with the impedance mismatch | + | * Programmers work in code, not HTML! |
- | Also allow web designers | + | * Mixing code and markup up is error prone and does not separate concerns. |
- | Web Tier as “Model View Controller” | + | * Recognising this, common pattern |
- | Web Tier is essentially | + | * Pattern // |
- | Principles: | + | |
- | Separation of presentation from model | + | |
- | Separation of controller from the view | + | |
- | In “Web Tier” | + | |
- | View is HTML or JSP page. | + | |
- | Controller is a Servlet. | + | |
- | Model is a Java (business) object. | + | |
- | MVC Patterns | + | |
- | Page Controller – an object that handles a request for a specific page or action on a web site. | + | |
- | Decode URL and extract any form data | + | |
- | Create and invoke any model objects to process the data. | + | |
- | Pass data to model (models don’t need to know about HTTP) | + | |
- | Determine which view should display the result and forward model info to view (JSP page). | + | |
- | MVC Patterns | + | |
- | Front Controller handles all requests for a web site | + | |
- | Used when navigation and application logic is more complex than can be reasonably handled by a collection of page controllers | + | |
- | Component Model | + | |
- | Pattern is based on “components” and events | + | |
- | Patterns in the Web Tier | + | ---- |
- | Implementing complex presentation logic in HTML is a complex task | + | |
- | Most of the Java EE Core Patterns are concerned with the presentation tier. | + | |
- | See full catalogue (online) at http:// | + | |
- | Study some for the seminar! | + | |
- | MVC Frameworks | + | |
- | Many common problems (as indicated by the large number of patterns for presentation tier) have been solved many times. | + | |
- | Many frameworks have been developed to simplify and standardise web tier development and implement the patterns. | + | |
- | All based around Servlets. Some also use or extend JSP. | + | |
- | Some examples (study for seminar): | + | |
- | Front Controller: | + | |
- | Apache Struts: http:// | + | |
- | Spring MVC: http:// | + | |
- | Component model: | + | |
- | Jakarta Tapestry: http:// | + | |
- | Java EE JavaServer Faces (JSF): http:// | + | |
+ | **Notes** | ||
- | Lecture Summary | + | Far from ideal models: |
- | Advantage of Java web container is that it is platform independent: will work on any machine that has a network connection and a JVM. | + | * Servlets: //HTML markup// embedded in print statements |
- | We have introduced some of the Java APIs that can be used to create web-based presentation services with Java. | + | * Groovlets: HTML markup // |
- | Servlets provide a way to create applications that communicate to a client via a web browser. | + | |
- | JSP allows the embedding of Java code inside an HTML page. | + | |
- | In the thin-client world you are not working alone! | + | |
- | Several core Java EE design patterns record best practice | + | |
- | Lab Exercises | + | ===== Groovy Server Pages ===== |
- | Download, install and run Tomcat | + | |
- | Modify ServletsRule.java so that the count i is loaded when the servlet starts (override init()) and is saved to disk by an overriden destroy() method. | + | |
- | Experiment with JSP pages. | + | |
- | Read-up on any or all of the Java EE patterns concerned with the presentation tier. | + | |
- | Look into alternative presentation tier technologies: | + | |
+ | * A possible implementation of the //Template View// pattern: | ||
+ | * Groovy has simpler syntax than Java so less of a problem | ||
+ | * Syntactically more forgiving | ||
+ | * Separation of concerns: | ||
+ | * can use Groovlet as a // | ||
+ | * web designer can work with view code (mostly HTML with simplified //view logic//) | ||
+ | * application developer can work with application logic in the controller. | ||
+ | * Good compromise between code-only servlet and Java-rich JSP. | ||
+ | | ||
+ | ===== Another example ===== | ||
+ | * Example from //Groovy in Action//: [[http:// | ||
+ | * This is the // | ||
+ | <code groovy 1|Example 14: Controller of HighLow game (at-m42/ | ||
+ | def session = request.session | ||
+ | def guess = params.guess | ||
+ | guess = guess ? guess.toInteger() : null | ||
+ | if (params.restart) guess = null | ||
+ | if (! session.goal || params.restart) { | ||
+ | session.goal = (Math.random() * 100).toInteger() | ||
+ | } | ||
+ | def goal = session.goal | ||
+ | // ... | ||
+ | </ | ||
+ | |||
+ | ===== Example (continued) ===== | ||
+ | |||
+ | <code groovy 1|Example 14: view for HighLow game (at-m42/ | ||
+ | // ... | ||
+ | |||
+ | html.html { head { title 'Think of a Number' | ||
+ | body { | ||
+ | h1 'Think of a Number' | ||
+ | if (goal && guess) { | ||
+ | div "Your guess is $guess " | ||
+ | if (guess == goal) { | ||
+ | div ' | ||
+ | } else if (guess < goal) { | ||
+ | div 'too low' | ||
+ | } else { | ||
+ | div 'too high' | ||
+ | } | ||
+ | } | ||
+ | p " | ||
+ | form(action : ' | ||
+ | input (type : ' | ||
+ | button (type : ' | ||
+ | button (type : ' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Adding GSP capabilities to Servlet container ===== | ||
+ | |||
+ | <code xml 1> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== A GSP View Page ===== | ||
+ | |||
+ | <code html l|Example 15(a): View for High-Low Game (at-m42/ | ||
+ | extern> http:// | ||
+ | </ | ||
+ | |||
+ | ===== The Controller: Dispatches to View ===== | ||
+ | |||
+ | * Revised controller Groovlet: [[http:// | ||
+ | <code groovy l|Example 15(b): Controller which dispatches to view (at-m42/ | ||
+ | extern> http:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Other Examples of Template View implementations ===== | ||
+ | * Not for discussion here. | ||
+ | * Java standard is to use " | ||
+ | * Tags look like XML tags (with namespaces) in (X)HTML pages. | ||
+ | * JSTL -- Java Standard Tag Library provides access to beans and provides simple programming logic tags. | ||
+ | * Can eliminate ''< | ||
+ | * Several open source alternatives: | ||
+ | * Best regarded seems to be // | ||
+ | * Very simple template language embedded in HTML -- similar to GSP | ||
+ | * Parsed and replaced by computational results (by a special Servlet) at access time. | ||
+ | * Transparent to web developers who just see HTML pages. | ||
+ | |||
+ | ===== Lecture Contents ===== | ||
+ | |||
+ | * [[#Servlets and Groovlets]] | ||
+ | * [[#Java Server Pages]] | ||
+ | * [[#Web Designers Want Templates Not Code!]] | ||
+ | * [[#Groovy Server Pages]] | ||
+ | * **[[# | ||
+ | |||
+ | ===== Architectural Issues: Patterns ===== | ||
+ | |||
+ | * Web container gets its requests from a web client in HTTP and returns HTML views of the application' | ||
+ | * Business objects are Java objects in the //business tier//. | ||
+ | * //Web Tier// communicates with the //Business Tier// either using some form of distributed computing technique or directly via Java/Groovy objects. | ||
+ | * Many presentation layer patterns are designed to simplify (or at least manage) the difficulties inherent with the "// | ||
+ | * Also allow web designers and programmers to do their things without stepping on each others toes. | ||
+ | |||
+ | ===== Web Tier as “Model View Controller” ====== | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | * Web Tier is essentially a good example of the classic [[wp> | ||
+ | * Principles: | ||
+ | * Separation of presentation from model | ||
+ | * Separation of controller from the view | ||
+ | * In "Web Tier" | ||
+ | * View is HTML or [G/J]SP page. | ||
+ | * Controller is a Servlet. | ||
+ | * Model is a (business) object. | ||
+ | |||
+ | ===== MVC Patterns in the Web Tier (1) ===== | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | {{: | ||
+ | |||
+ | * Decode URL and extract any form data | ||
+ | * Create and invoke any model objects to process the data. | ||
+ | * Pass data to model (models don’t need to know about HTTP) | ||
+ | * Determine which view should display the result and forward model info to view (template page). | ||
+ | |||
+ | ===== MVC Patterns in the Web Tier (2) ===== | ||
+ | |||
+ | [[http:// | ||
+ | * Used when navigation and application logic is more complex than can be reasonably handled by a collection of page controllers. | ||
+ | {{: | ||
+ | {{ : | ||
+ | |||
+ | ===== Component Model ===== | ||
+ | |||
+ | Pattern is based on " | ||
+ | {{: | ||
+ | |||
+ | ===== Patterns in the Web Tier ===== | ||
+ | * Implementing complex presentation logic in HTML is a complex task | ||
+ | * Most of the Java EE Core Patterns are concerned with the presentation tier. | ||
+ | * See full catalogue ([[http:// | ||
+ | ===== MVC Frameworks ===== | ||
+ | |||
+ | * Many common problems (as indicated by the large number of patterns for presentation tier) have been solved many times. | ||
+ | * Many frameworks have been developed to simplify and standardise web tier development and implement the patterns. | ||
+ | * All based around Servlets. Some also use or extend JSP. | ||
+ | |||
+ | ===== Some Example Frameworks ===== | ||
+ | |||
+ | //Front Controller//: | ||
+ | * Apache Struts: http:// | ||
+ | * Spring MVC: http:// | ||
+ | //Component model//: | ||
+ | * Apache Tapestry: http:// | ||
+ | * Java EE JavaServer Faces (JSF): http:// | ||
+ | * Google Web Toolkit (GWT): http:// | ||
+ | |||
+ | Many more [[http:// | ||
+ | |||
+ | ===== Lecture Summary ===== | ||
+ | |||
+ | * Advantage of Java web container is that it is platform independent: | ||
+ | * We have introduced some of the Java APIs that can be used to create web-based presentation services with Java. | ||
+ | * Servlets provide a way to create applications that communicate to a client via a web browser. | ||
+ | * JSP allows the embedding of Java code inside an HTML page. | ||
+ | * Groovy makes both Servlets (Groovlets) and Templates (GSP) easier. | ||
+ | * In the thin-client world you are not working alone: | ||
+ | * Several core Java EE design patterns record best practice and have been implemented in open source and official Java solutions. | ||
---- | ---- | ||
[[Home]] | [[lecture12|Previous Lecture]] | [[Lectures]] | [[lecture14|Next Lecture]] | [[Home]] | [[lecture12|Previous Lecture]] | [[Lectures]] | [[lecture14|Next Lecture]] | ||
- |
at-m42/lecture13.1240334564.txt.gz · Last modified: 2011/01/14 12:23 (external edit)