User Tools

Site Tools


at-m42:lecture13

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
at-m42:lecture13 [2009/04/22 08:02] eechrisat-m42:lecture13 [2011/01/14 12:45] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ~~SLIDESHOW~~ ~~SLIDESHOW~~
-====== Presentation Tier Services ======+====== 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 477: Line 477:
   * Good compromise between code-only servlet and Java-rich JSP.   * Good compromise between code-only servlet and Java-rich JSP.
      
 +===== Another example =====
 +  * Example from //Groovy in Action//: [[http://localhost:8080/at-m42-examples/HighLow.groovy|HighLow.groovy]].
 +  * This is the //controller//:
 +
 +<code groovy 1|Example 14: Controller of HighLow game (at-m42/Examples/lecture13/web/HighLow.groovy)>
 +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
 +
 +// ...
 +</code>
 +
 +===== Example (continued) =====
 +
 +<code groovy 1|Example 14: view for HighLow game (at-m42/Examples/lecture13/web/HighLow.groovy)>
 +// ...
 +
 +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 'correct!'
 +            } else if (guess < goal) {
 +            div 'too low' 
 +            } else {
 +                div 'too high'
 +            }
 +        }
 +        p "What's your guess (0..100)?"
 +        form(action : 'HighLow.groovy') {
 +            input (type : 'text', name : 'guess', '')
 +            button (type : 'submit', 'Guess')
 +            button (type : 'submit', name : 'restart', value : 'true', 'New Game')
 +        }
 +    }
 +}
 +</code>
  
 ===== Adding GSP capabilities to Servlet container ===== ===== Adding GSP capabilities to Servlet container =====
  
 +<code xml 1>
 +<servlet>
 +    <servlet-name>Groovy Server Pages</servlet>
 +    <servlet-class>groovy.template.TemplateServlet</servlet-class>
 +</servlet>
 +
 +<servlet-mapping>
 +    <servlet-name>Groovy Server Pages</servlet-name>
 +    <url-pattern>*.gsp</url-pattern>
 +</servlet-mapping>
 +</code>
 +
 +===== A GSP View Page =====
 +
 +<code html l|Example 15(a): View for High-Low Game (at-m42/Examples/lecture13/web/HighLow.gsp)>
 +extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture13/web/HighLow.gsp
 +</code>
 +
 +===== The Controller: Dispatches to View =====
 +
 +  * Revised controller Groovlet: [[http://localhost:8080/at-m42-examples/HighLow.groovy|HighLow2.groovy]].
 +<code groovy l|Example 15(b): Controller which dispatches to view (at-m42/Examples/lecture13/web/HighLow2.groovy)>
 +extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture13/web/HighLow2.groovy
 +</code>
  
  
Line 581: Line 651:
  
 [[Home]] | [[lecture12|Previous Lecture]] | [[Lectures]] | [[lecture14|Next Lecture]]  [[Home]] | [[lecture12|Previous Lecture]] | [[Lectures]] | [[lecture14|Next Lecture]] 
- 
at-m42/lecture13.1240387327.txt.gz · Last modified: 2011/01/14 12:23 (external edit)