SlideShare a Scribd company logo
An Introduction to
Building Web Application Using
   Jakarta Struts Framework
   Presented to Indianapolis Java User Group

                   10/30/2002

                     Wei Li
Challenge from Building Web
          Applications
• Stateless protocol
• Multiple tiers
• …
Building Web Application with
      Java - Why it is good
• Build once, run everywhere (platform-
  independent, vendor-independent)
• Build it in an object-oriented way
• Reusable components
• Flexible and easy to be maintained and extended
Building Web Application with
         Java - choices
• Pure Java Servlets (control + presentation)
• Java Servlets (control) + template engine
  (presentation) (Velocity, WebMacro, Tea)
• Java Servlets (control) + XML and XSLT
  (presentation)
• JSP (presentation + control) + Java Beans
  (control+model) (Model 1)
• JSP(presentation) + Java Servlets (control)+ Java
  Beans (model) (Model 2)
Problems with Pure Java
             Servlets - sample code
 public void printHTMLReport(PrintWriter out, Results results) {
  println(out, "<b>Poll:</b> " + poll.getId() + "<br>");
  println(out, "<b>Question:</b> " + poll.getQuestion() + "<br>");
  out.print("<b>Candidates:</b> ");
  this.printCandidates(out);
  println(out, "<br>");
  println(out, "<br>");
  println(out, "<b>The winner is...</b> " + results.getWinner() + "!<br>");
  println(out, "<br><br>");
  println(out, "Round-by-round summary:<br><br>");
…
…
}
Problems with Pure Java
              Servlets
• Servlets have to take care of presentation - which
  is not a good thing for it to do
• HTML tags in the Java code
• Hard to maintain and extend (every content
  change requires the compilation of Java classes)
• Frustration of Java developers who are good at
  writing Java code but not HTML
Problems with JSPs + Java Beans
          (Model 1)
No controller - each page is responsible to direct control to the
  next page.




      request

                   JSP             Java               EIS
      response
                                   Beans
Problems with JSPs + Java Beans
          (Model 1)
• Java code in HTML tags
• Hard to maintain and change also
• Frustration of content developer
MVC and Model II
• Aim to separate the flow control, business logic
  and presentation
MVC and Model II
• Model - this is you data in the system. Such as a poll, the
  profile of a poll administrator.
• View - how data is represented to the user. For instance
  the view in a web application could be an HTML page, an
  image or other media.
• Controller - is the glue between the model and the view.
  It is responsible for controlling the flow as well as
  processing updates from the model to the view and visa
  versa
MVC and Model II
• Model II - uses a controller

                                      Web container
   1. request
                Controller
                                 2


                      3              Model            EIS
                             4
5. response
                 View
MVC and Model II

• Controller - Java servelts
• Model - Java Beans (domain objects, value
  objects)
• View - JSP, XML + XSLT ….
MVC and Model II

•   Many implementations available for choice
•   Expresso
•   Barracuda
•   Cocoon
•   WebWork
•   Velocity, Tea, WebMacro
•   ….
MVC and Model II

• And of course, you can build your own
• But, Why? Regardless how you implement, you
  probably will end up with something similar or
  close to Struts.
Break 1

A good scientist is a person with original ideas. A
  good engineer is a person who makes a design that
  works with as few original ideas as possible.

                             --- Freeman Dyson
Jakarta Struts - What is it?
• A flexible control layer based on standard technologies
  like Java Servlets, JavaBeans, ResourceBundles, and
  Extensible Markup Language (XML).
• An implementation of MVC Model II
• A standardized and extensible web application
  design/implementation framework
Jakarta Struts - General Info
• Craig McClanahan created the original framework and
  donated it to Apache Software Foundation (ASF) in 2000.
• Current stable release - 1.0.2.
• 1.1 is in beta release.
• The framework provides 9 package with 250 classes
Jakarta Struts - Features
• An Model II implementation of MVC
• Big base packages and classes ready to use
• Rich Custom Tag Libraries ready to use
• Easy support for internationalization (I18N)
Jakarta Struts - the whole picture
                                       configuration     configuration
                                     Struts-config.xml
 request    ActionServlet            Message Bundle

                        Controller
           action
               action
                    action
                                                            EIS
                                          Model

response         View
                                        Java Beans,
           JSP, Tag Library
                                        EJB, ...
           ….
Jakarta Struts - the controller

• ActionServlet - Responsible for flow of control - 1.
  receive all requests, 2. route/delegate request to Action for
  handling, 3. return response
• One instance per web application
• Uses a configuration file called struts-config.xml to read
  mapping data, which specify control flow information
• Provided by the framework already. Ready to use but can
  also be extended
Jakarta Struts - the controller
• Action - the actual class which processes the
  request relevant to the business operation. Based
  on action mappings defined in an XML
  configuration file, the controller dispatches a call
  to the perform method of the appropriate Action
  Class.
• Command pattern
• Framework provides some actions. You need to
  implement you own action class for business
  purpose.
Jakarta Struts - the model

• You are responsible for creating it - Java Bean,
  EJB, etc.
• Should be reusable domain objects and value
  objects to represent a state.
• The framework works fine with any model
  implementation.
Jakarta Struts - the view

• JSP
• Custom Tag Library
• Resource Bundle
Jakarta Struts - the view

• Struts provides rich custom tag library to
  dramatically reduce Java code in your jsp.

• Example: HTML, BEAN, LOGIC,
  TEMPLATES,…

• We will see how handy they are in the case study
Jakarta Struts - the others

• ActionForm - encapsulate request/session data,
  typically used for input forms, provides a central
  point to validate form data.
Jakarta Struts - the others

• ActionMessage and ActionError
Jakarta Struts - the configuration

• Glue the system together
• web.xml and struts-config.xml
Jakarta Struts - the configuration

• Web.xml:
  o define the controller servlet (ActionServlet)with initial parameters;
  o define URL mapping to be handled by the controller servlet;
  o define the Struts tag libraries.
Jakarta Struts - the configuration

• struts-config.xml
   o Glue all components together and set the rules for the
     application
   o Data Source Configuration
   o Form Bean Definitions
   o Action Mapping Definitions
   o Global Forward Definitions
Break 2
A manager, an engineer, and a developer are going down a
  hill in a jeep when it suddenly loses control and goes into a
  ditch. They each attempt to offer a solution to the problem.
  The manager says 'Let's have a meeting to discuss a
  solution'. The engineer says 'Let's disassemble the jeep,
  and examine every part to find out where the problem is.'
  The developer says, 'Let's push it back up the hill and try
  again.

         http://www.middleware-company.com/offer/patternsday1/article4.shtml
Case Study:
          An Online Instant Poll
• Introduction - When I was having a hard time to define an
  appropriate application to really have my hands wet with
  Struts, I spotted Alex Chaffee’s JiffyPoll
  (http://www.purpletech.com/irv/index.html). I like his
  idea but not all his implementation. Then I began to apply
  the struts framework to it and extends its functionality …
Case Study:
         An Online Instant Poll
• What does it do?
   o As a normal user - you can select and vote a poll, you
     can view the results of any poll, you can also see the
     information about a poll.
   o As an administrator - you can create a new poll right
     away. You can also disable/enable a poll owned by you.
Case Study:
         An Online Instant Poll
• What does it do - Let us try it.
Case Study:
                 An Online Instant Poll
                                                                        Flat text file
            Web container                                              as persistence
                                 Service interface
                                                                           media
  request                                   PlainTextFilePollService
             controller     Service            DatabasePollService
                            factory                                      Relational
                                                 EJBPollService          Database


response
                view                     model                         EJB Container
Case Study:
         An Online Instant Poll
• Benefits of the design
   o The real business logic is de-coupled from the
     controller, the model and the view
   o Increase of the reusability of the components - the
     service is completely reusable, the model (domain
     object and value object) is fully reusable also.
Case Study:
         An Online Instant Poll
• The controller - directly use ActionServlet
  provided by the framework

• The action classes - delegate to service provider
  which does the real work.
Case Study:
        An Online Instant Poll
• The real business logic - de-coupled from the
  framework and stands as a independent/reusable
  component
Case Study:
        An Online Instant Poll
• The Model - reusable Java Beans, domain objects
  and value objects.
Case Study:
        An Online Instant Poll
• The view - use the data provided in the model
• Rich use of tag library provide by the framework

• Show some sample JSPs and includes

• Almost no Java code in JSPs
Case Study:
         An Online Instant Poll
• Internationalization - easy to be implemented like
  a breeze

• Demo
Jakarta Struts - Why it is good

• Promote clean separation of components
Jakarta Struts - Why it is good

• Increase the modularity, reusability of components
Jakarta Struts - Why it is good

• Focus on design
Jakarta Struts - Why it is good

• Very use case driven
Jakarta Struts - Why it is good

• What you need to do is clear
• You can really focus on the real work - the
  business logic
Jakarta Struts - Why it is good

• Easy internationalization
Jakarta Struts - Why it is good

•   Free
•   Open Source
•   Implemented by savvy developer/expert
•   large user community
New features in 1.1 - what makes
            it better
• Declarative exception handling
<action path="/login"
        type="net.indyjug.weili.struts.security.LoginAction"
        name="loginForm"
        scope="request"
        validate="true"
        input="/jsp/login.jsp">
        <exception
             key="error.invalidlogin"
             path=”/jsp/login.jsp"
             scope="request"
             type=”net.indyjug.weili.struts.exception.InvalidLoginException"/>
        <forward name="success" path="/jsp/administration.jsp" />
        <forward name="failure" path="/jsp/login.jsp" />
 </action>
New features in 1.1 - what makes
            it better
• Dynamic Form Bean
New features in 1.1 - what makes
            it better
• Plug-in
New features in 1.1 - what makes
            it better
• Tiles
The learning curve

• Not so easy for the first time. After that life is
  easy.
• Manageable
• Custom tag library may make mad at the
  beginning. Do not quit. They are so handy once
  you know how to use them.
Fast Track:
              Getting Started
• What you need
  o JDK 1.2 and above
  o Web Contained compliant with Servlet API 2.2 and JSP
    API 1.1
  o An XML parser compliant with JAXP 1.1 or above
    (this is usually provided by the web container)
Fast Track:
             Getting Started
• The framework provides an application template
  for you to use and extend
• Always continue on top of something which is
  working.
• Build the whole structure first and leave the
  concrete implementation later on (example)
Question?
Ad

More Related Content

What's hot (20)

3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
myrajendra
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatis
Will Iverson
 
CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287
Ahmad Gohar
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
Rajiv Gupta
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
balassaitis
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
myrajendra
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
myrajendra
 
7장 Oracle As Datasource
7장 Oracle As Datasource7장 Oracle As Datasource
7장 Oracle As Datasource
김 한도
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
Long Nguyen
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Paul Jones
 
2장. Runtime Data Areas
2장. Runtime Data Areas2장. Runtime Data Areas
2장. Runtime Data Areas
김 한도
 
Mock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleMock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion Principle
P Heinonen
 
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next LevelMWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
balassaitis
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
Hitesh-Java
 
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVCJava EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Josh Juneau
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
divzi1913
 
Spring framework
Spring frameworkSpring framework
Spring framework
Aircon Chen
 
4장. Class Loader
4장. Class Loader4장. Class Loader
4장. Class Loader
김 한도
 
6장 Thread Synchronization
6장 Thread Synchronization6장 Thread Synchronization
6장 Thread Synchronization
김 한도
 
5장. Execution Engine
5장. Execution Engine5장. Execution Engine
5장. Execution Engine
김 한도
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatis
Will Iverson
 
CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287
Ahmad Gohar
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
balassaitis
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
myrajendra
 
7장 Oracle As Datasource
7장 Oracle As Datasource7장 Oracle As Datasource
7장 Oracle As Datasource
김 한도
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
Long Nguyen
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Paul Jones
 
2장. Runtime Data Areas
2장. Runtime Data Areas2장. Runtime Data Areas
2장. Runtime Data Areas
김 한도
 
Mock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleMock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion Principle
P Heinonen
 
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next LevelMWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
balassaitis
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
Hitesh-Java
 
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVCJava EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Josh Juneau
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
divzi1913
 
Spring framework
Spring frameworkSpring framework
Spring framework
Aircon Chen
 
4장. Class Loader
4장. Class Loader4장. Class Loader
4장. Class Loader
김 한도
 
6장 Thread Synchronization
6장 Thread Synchronization6장 Thread Synchronization
6장 Thread Synchronization
김 한도
 
5장. Execution Engine
5장. Execution Engine5장. Execution Engine
5장. Execution Engine
김 한도
 

Viewers also liked (10)

Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
guest764934
 
Introduction to Struts 2
Introduction to Struts 2Introduction to Struts 2
Introduction to Struts 2
Collaboration Technologies
 
Frameworks in java
Frameworks in javaFrameworks in java
Frameworks in java
Darshan Patel
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
elliando dias
 
Struts Basics
Struts BasicsStruts Basics
Struts Basics
Harjinder Singh
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
Syed Shahul
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
Bryan Hsueh
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
MD Sayem Ahmed
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
JayaPrakash.m
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
guest764934
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
elliando dias
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
Syed Shahul
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
Bryan Hsueh
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
MD Sayem Ahmed
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
Ad

Similar to Build Java Web Application Using Apache Struts (20)

JAVA EE training from 3rd-oct-2015
JAVA EE training from 3rd-oct-2015JAVA EE training from 3rd-oct-2015
JAVA EE training from 3rd-oct-2015
Naz Ish
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
Ashton Feller
 
Advance java1.1
Advance java1.1Advance java1.1
Advance java1.1
Prince Soni
 
MVC + ORM (with project implementation)
MVC + ORM (with project implementation)MVC + ORM (with project implementation)
MVC + ORM (with project implementation)
Prateek Chauhan
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
vipin kumar
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
skill-guru
 
170215 msa intro
170215 msa intro170215 msa intro
170215 msa intro
Sonic leigh
 
J2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for womenJ2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for women
lissa cidhi
 
What is ASP.NET MVC
What is ASP.NET MVCWhat is ASP.NET MVC
What is ASP.NET MVC
Brad Oyler
 
Spring - a framework written by developers
Spring - a framework written by developersSpring - a framework written by developers
Spring - a framework written by developers
MarcioSoaresPereira1
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
Dimitri de Putte
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
Chris Aniszczyk
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
Mukesh Kumar
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
pavanteja86
 
What's New in IBM Java 8 SE?
What's New in IBM Java 8 SE?What's New in IBM Java 8 SE?
What's New in IBM Java 8 SE?
Tim Ellison
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
Anup72
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
Abhishek Sur
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
Kevin Webber
 
Virtual classroom
Virtual classroomVirtual classroom
Virtual classroom
Krishna Chaithanya
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
netc2012
 
JAVA EE training from 3rd-oct-2015
JAVA EE training from 3rd-oct-2015JAVA EE training from 3rd-oct-2015
JAVA EE training from 3rd-oct-2015
Naz Ish
 
MVC + ORM (with project implementation)
MVC + ORM (with project implementation)MVC + ORM (with project implementation)
MVC + ORM (with project implementation)
Prateek Chauhan
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
vipin kumar
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
skill-guru
 
170215 msa intro
170215 msa intro170215 msa intro
170215 msa intro
Sonic leigh
 
J2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for womenJ2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for women
lissa cidhi
 
What is ASP.NET MVC
What is ASP.NET MVCWhat is ASP.NET MVC
What is ASP.NET MVC
Brad Oyler
 
Spring - a framework written by developers
Spring - a framework written by developersSpring - a framework written by developers
Spring - a framework written by developers
MarcioSoaresPereira1
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
Dimitri de Putte
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
Mukesh Kumar
 
What's New in IBM Java 8 SE?
What's New in IBM Java 8 SE?What's New in IBM Java 8 SE?
What's New in IBM Java 8 SE?
Tim Ellison
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
Anup72
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
Abhishek Sur
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
Kevin Webber
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
netc2012
 
Ad

Recently uploaded (20)

AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 

Build Java Web Application Using Apache Struts

  • 1. An Introduction to Building Web Application Using Jakarta Struts Framework Presented to Indianapolis Java User Group 10/30/2002 Wei Li
  • 2. Challenge from Building Web Applications • Stateless protocol • Multiple tiers • …
  • 3. Building Web Application with Java - Why it is good • Build once, run everywhere (platform- independent, vendor-independent) • Build it in an object-oriented way • Reusable components • Flexible and easy to be maintained and extended
  • 4. Building Web Application with Java - choices • Pure Java Servlets (control + presentation) • Java Servlets (control) + template engine (presentation) (Velocity, WebMacro, Tea) • Java Servlets (control) + XML and XSLT (presentation) • JSP (presentation + control) + Java Beans (control+model) (Model 1) • JSP(presentation) + Java Servlets (control)+ Java Beans (model) (Model 2)
  • 5. Problems with Pure Java Servlets - sample code public void printHTMLReport(PrintWriter out, Results results) { println(out, "<b>Poll:</b> " + poll.getId() + "<br>"); println(out, "<b>Question:</b> " + poll.getQuestion() + "<br>"); out.print("<b>Candidates:</b> "); this.printCandidates(out); println(out, "<br>"); println(out, "<br>"); println(out, "<b>The winner is...</b> " + results.getWinner() + "!<br>"); println(out, "<br><br>"); println(out, "Round-by-round summary:<br><br>"); … … }
  • 6. Problems with Pure Java Servlets • Servlets have to take care of presentation - which is not a good thing for it to do • HTML tags in the Java code • Hard to maintain and extend (every content change requires the compilation of Java classes) • Frustration of Java developers who are good at writing Java code but not HTML
  • 7. Problems with JSPs + Java Beans (Model 1) No controller - each page is responsible to direct control to the next page. request JSP Java EIS response Beans
  • 8. Problems with JSPs + Java Beans (Model 1) • Java code in HTML tags • Hard to maintain and change also • Frustration of content developer
  • 9. MVC and Model II • Aim to separate the flow control, business logic and presentation
  • 10. MVC and Model II • Model - this is you data in the system. Such as a poll, the profile of a poll administrator. • View - how data is represented to the user. For instance the view in a web application could be an HTML page, an image or other media. • Controller - is the glue between the model and the view. It is responsible for controlling the flow as well as processing updates from the model to the view and visa versa
  • 11. MVC and Model II • Model II - uses a controller Web container 1. request Controller 2 3 Model EIS 4 5. response View
  • 12. MVC and Model II • Controller - Java servelts • Model - Java Beans (domain objects, value objects) • View - JSP, XML + XSLT ….
  • 13. MVC and Model II • Many implementations available for choice • Expresso • Barracuda • Cocoon • WebWork • Velocity, Tea, WebMacro • ….
  • 14. MVC and Model II • And of course, you can build your own • But, Why? Regardless how you implement, you probably will end up with something similar or close to Struts.
  • 15. Break 1 A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible. --- Freeman Dyson
  • 16. Jakarta Struts - What is it? • A flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and Extensible Markup Language (XML). • An implementation of MVC Model II • A standardized and extensible web application design/implementation framework
  • 17. Jakarta Struts - General Info • Craig McClanahan created the original framework and donated it to Apache Software Foundation (ASF) in 2000. • Current stable release - 1.0.2. • 1.1 is in beta release. • The framework provides 9 package with 250 classes
  • 18. Jakarta Struts - Features • An Model II implementation of MVC • Big base packages and classes ready to use • Rich Custom Tag Libraries ready to use • Easy support for internationalization (I18N)
  • 19. Jakarta Struts - the whole picture configuration configuration Struts-config.xml request ActionServlet Message Bundle Controller action action action EIS Model response View Java Beans, JSP, Tag Library EJB, ... ….
  • 20. Jakarta Struts - the controller • ActionServlet - Responsible for flow of control - 1. receive all requests, 2. route/delegate request to Action for handling, 3. return response • One instance per web application • Uses a configuration file called struts-config.xml to read mapping data, which specify control flow information • Provided by the framework already. Ready to use but can also be extended
  • 21. Jakarta Struts - the controller • Action - the actual class which processes the request relevant to the business operation. Based on action mappings defined in an XML configuration file, the controller dispatches a call to the perform method of the appropriate Action Class. • Command pattern • Framework provides some actions. You need to implement you own action class for business purpose.
  • 22. Jakarta Struts - the model • You are responsible for creating it - Java Bean, EJB, etc. • Should be reusable domain objects and value objects to represent a state. • The framework works fine with any model implementation.
  • 23. Jakarta Struts - the view • JSP • Custom Tag Library • Resource Bundle
  • 24. Jakarta Struts - the view • Struts provides rich custom tag library to dramatically reduce Java code in your jsp. • Example: HTML, BEAN, LOGIC, TEMPLATES,… • We will see how handy they are in the case study
  • 25. Jakarta Struts - the others • ActionForm - encapsulate request/session data, typically used for input forms, provides a central point to validate form data.
  • 26. Jakarta Struts - the others • ActionMessage and ActionError
  • 27. Jakarta Struts - the configuration • Glue the system together • web.xml and struts-config.xml
  • 28. Jakarta Struts - the configuration • Web.xml: o define the controller servlet (ActionServlet)with initial parameters; o define URL mapping to be handled by the controller servlet; o define the Struts tag libraries.
  • 29. Jakarta Struts - the configuration • struts-config.xml o Glue all components together and set the rules for the application o Data Source Configuration o Form Bean Definitions o Action Mapping Definitions o Global Forward Definitions
  • 30. Break 2 A manager, an engineer, and a developer are going down a hill in a jeep when it suddenly loses control and goes into a ditch. They each attempt to offer a solution to the problem. The manager says 'Let's have a meeting to discuss a solution'. The engineer says 'Let's disassemble the jeep, and examine every part to find out where the problem is.' The developer says, 'Let's push it back up the hill and try again. http://www.middleware-company.com/offer/patternsday1/article4.shtml
  • 31. Case Study: An Online Instant Poll • Introduction - When I was having a hard time to define an appropriate application to really have my hands wet with Struts, I spotted Alex Chaffee’s JiffyPoll (http://www.purpletech.com/irv/index.html). I like his idea but not all his implementation. Then I began to apply the struts framework to it and extends its functionality …
  • 32. Case Study: An Online Instant Poll • What does it do? o As a normal user - you can select and vote a poll, you can view the results of any poll, you can also see the information about a poll. o As an administrator - you can create a new poll right away. You can also disable/enable a poll owned by you.
  • 33. Case Study: An Online Instant Poll • What does it do - Let us try it.
  • 34. Case Study: An Online Instant Poll Flat text file Web container as persistence Service interface media request PlainTextFilePollService controller Service DatabasePollService factory Relational EJBPollService Database response view model EJB Container
  • 35. Case Study: An Online Instant Poll • Benefits of the design o The real business logic is de-coupled from the controller, the model and the view o Increase of the reusability of the components - the service is completely reusable, the model (domain object and value object) is fully reusable also.
  • 36. Case Study: An Online Instant Poll • The controller - directly use ActionServlet provided by the framework • The action classes - delegate to service provider which does the real work.
  • 37. Case Study: An Online Instant Poll • The real business logic - de-coupled from the framework and stands as a independent/reusable component
  • 38. Case Study: An Online Instant Poll • The Model - reusable Java Beans, domain objects and value objects.
  • 39. Case Study: An Online Instant Poll • The view - use the data provided in the model • Rich use of tag library provide by the framework • Show some sample JSPs and includes • Almost no Java code in JSPs
  • 40. Case Study: An Online Instant Poll • Internationalization - easy to be implemented like a breeze • Demo
  • 41. Jakarta Struts - Why it is good • Promote clean separation of components
  • 42. Jakarta Struts - Why it is good • Increase the modularity, reusability of components
  • 43. Jakarta Struts - Why it is good • Focus on design
  • 44. Jakarta Struts - Why it is good • Very use case driven
  • 45. Jakarta Struts - Why it is good • What you need to do is clear • You can really focus on the real work - the business logic
  • 46. Jakarta Struts - Why it is good • Easy internationalization
  • 47. Jakarta Struts - Why it is good • Free • Open Source • Implemented by savvy developer/expert • large user community
  • 48. New features in 1.1 - what makes it better • Declarative exception handling <action path="/login" type="net.indyjug.weili.struts.security.LoginAction" name="loginForm" scope="request" validate="true" input="/jsp/login.jsp"> <exception key="error.invalidlogin" path=”/jsp/login.jsp" scope="request" type=”net.indyjug.weili.struts.exception.InvalidLoginException"/> <forward name="success" path="/jsp/administration.jsp" /> <forward name="failure" path="/jsp/login.jsp" /> </action>
  • 49. New features in 1.1 - what makes it better • Dynamic Form Bean
  • 50. New features in 1.1 - what makes it better • Plug-in
  • 51. New features in 1.1 - what makes it better • Tiles
  • 52. The learning curve • Not so easy for the first time. After that life is easy. • Manageable • Custom tag library may make mad at the beginning. Do not quit. They are so handy once you know how to use them.
  • 53. Fast Track: Getting Started • What you need o JDK 1.2 and above o Web Contained compliant with Servlet API 2.2 and JSP API 1.1 o An XML parser compliant with JAXP 1.1 or above (this is usually provided by the web container)
  • 54. Fast Track: Getting Started • The framework provides an application template for you to use and extend • Always continue on top of something which is working. • Build the whole structure first and leave the concrete implementation later on (example)