Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/us/
Agenda
Web application architecture Java Servlet technology WebWork: building webapps made easy Spring: Inversion of Control (IoC) Maven: Java project management and build tool
Source: http://www.ibm.com/developerworks/ibm/library/it-booch_web/
Stateless communication
Communications between your browser and the Web Server is usually stateless Cookie was invented to solve this problem.
Where do you place your business logic? Thin client: most of the business logic live on the client side Thick client: application states are managed by the server
Raw data
HTML
SQL DB
A major part of the application implementation consists of accessing and updating the raw data which can be costly. Reduce this overhead can speed up your development (i.e., save cost)
Framework
Software engineering is like civil engineering: we need framework.
Option1: Build everything from scratch
Your Goal
Java
Java Apache Cocoon Apache Struts AppFuse Aranea framework Click [fleXive] Google Web Toolkit Grails Hamlets ICEfaces IT Mill Toolkit ItsNat JavaServer Faces
ColdFusion
Source: http://www.informit.com/articles/article.aspx?p=26920
HelloWorld Servlet
Implementation that handles HTTP GET request
Source: http://www.informit.com/articles/article.aspx?p=26920
JSP
Write code deploy
HelloWorld JSP
Source: http://mainline.brynmawr.edu/~dkumar/JSP/
MVC: Model-View-Control
Java BluePrints developed a recommended design pattern for building Java Servlet applications Goal: help you to design, implement and maintain your Java Web applications
http://java.sun.com/blueprints/patterns/MVC-detailed.html
HTML, PDF and whatever goes here. They read and parse data object from the Model
WebWork
WebWork
A Java MVC framework that help developers to minimize code and to be more concentrated on business logic and modeling. Less plumbing code, more useful code.
http://www.opensymphony.com/webwork/
WebWork terminology
Action: a piece of code that is executed when a URL is visited Bean: a data object that holds useful application information Views: templates pages for generating outputs for the clients to consume. Result: the output created by a template page
WebWork workflow
Read: http://www.javaworld.com/javaworld/jw-03-2004/jw-0329-webwork.html
WebWork HelloWorld
Goal: Go a URL, the webapp outputs Hello World! 3 Steps
Create an Action class to handle the request Create a View (template) to produce HTML Configure Action and View
Action: HelloWorld.java
Extends a standard Action superclass.
View: helloworld.jsp
If you dont like to use JSP, you have other options: Freemarker and Velocity
Read: http://www.javaworld.com/javaworld/jw-10-2005/jw-1010-webwork.html
Spring IoC
Problem: The use of MovieFinderImpl is hardwired into MovieLister. Change this logic will require code rewrite and re-compile MovieFinderImpl
IoC Solution
Introduce an intermediate component to handle the assembly of class objects.
<creates>
Solution: If you want to use a different MovieFinder, just change how Assembler calls <creates>.
Spring IoC
A framework that can be coupled with WebWork to provide Dependency Injection.
Spring IoC implements a flexible Assembler.
Developers can tell this Assembler how to perform <create> via XML configuration.
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html
http://code.google.com/p/gnizr/wiki/HelloWorldDemo
(1)
(2)
(1) The Class object folderTagListener is dynamically associated with bookmarkManager via a configuration file, not hardwired in the source of bookmarkManager. (2) Developers also fine tune the number of WorkerThread to be instantiated by bookmarkManager in the same configuration file.
Apache Maven
- Why do you think its important to consider those issues when building software?
- Can you relate to what you have experienced in the past (in school or at work)?
Apache Maven
Maven is an open source Java project management tool that simplifies many of the tedious tasks associated with Java programming. Features I love very much:
Library dependency management Build, test, and package Pre-defined directory layout for webapp dev.
http://maven.apache.org/
POM file
In Make, we have Makefile In Maven, we have POM file (pom.xml) In this POM file, you can define
JAR (version and package names) that should to be included in your build CLASSPATH (dependencies). The layout of your project (where do you keep source, .class, other resources and configuration) Information for generating documentation And many other stuff
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
Summary
Building a successful and maintainable Java Web application requires the effective use of software frameworks and development tools. WebWork and Spring are excellent frameworks for building scalable and high-quality Java Web applications. Apache Maven solves many project management issues that programmers have been struggling for a long time.