Apache Struts Technology A MVC Framework for Java Web Applications.

Slides:



Advertisements
Similar presentations
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Advertisements

Apache Struts Technology
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Web MVC-2: Apache Struts Rimon Mikhaiel
MVC Frameworks Alternatives to coding the MVC pattern.
Struts1 Apache Struts Dr Jim Briggs. Struts2 What is Struts? Struts is an open source framework for building Java web applications Supports MVC/Model.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
J2EE Java2 Enterprise Edition by Damian Borth. Contents Introduction Architectures styles Components Scenarios Roles Processing a HTTP request.
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Apache Struts Technology A MVC Framework for Java Web Applications.
Session-01. Layers Struts 2 Framework The struts 2 framework is used to develop MVC-based web application. Struts 1.0 was released in June The.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Struts 2.0 an Overview ( )
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
Introduction to the Jakarta Struts Framework  The Topics: JavaServer Pages (JSP) Overview JSP Tags and Tag Libraries Overview Model – View – Controller.
JavaServer Faces: The Fundamentals Compiled from Sun TechDays workshops (JSF Basics, Web-Tier Codecamp: JavaServer Faces, Java Studio Creator; IBM RAD)
1 INTRO TO BUSINESS COMPONENTS FOR JAVA (BC4J) Matt Fierst Computer Resource Team OracleWorld Session
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Introduction to MVC and the Jakarta Struts Framework By Gyanendra Dwivedi Software Consultant.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Introduction to J2EE Architecture Portions by Kunal Mehta.
Jakarta Struts Presented by Object Computing, Inc. (OCI) Written by Greg Elliott
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
Standalone Java Application vs. Java Web Application
J2EE Structure & Definitions Catie Welsh CSE 432
8/15/2003System Specialists Corporation How to implement BC4J with the Struts Framework Eugene Sicat Technical Architect/Project Manager System Specialists.
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
Fall CIS 764 Database Systems Design L8. Web ….
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
J2EE Struts 1 3 Struts: Introduction 1 4 Once you’ve coded a lot of JSP applications, you find yourself doing a lot of repetitive things. Also,
Model View Controller Architecture of Java Web Applications Dr. M V S Peri Sastry, Ph.D.[BITS-Pilani]
Enterprise Java Beans. Model 1 J2EE – Web View Model/View/Controller Model View Control Data base Web Server Model One Architecture HTTP Request HTTP.
Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
1 Copyright © 2004, Oracle. All rights reserved. Oracle Application Development Framework.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
11 Copyright © 2004, Oracle. All rights reserved. Customizing Actions.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
An Introduction to and This document is for purely educational purposes.
Introduction to Jakarta Struts Framework Try NCCU Computer Center Mar 20,2002.
Introduction to J2EE Architecture
Unit 6-Chapter 2 Struts.
Introduction to Struts
Distributed System Using Java 2 Enterprise Edition (J2EE)
The Model Layer What is Model?
JavaServer Faces: The Fundamentals
Struts BY: Tejashri Udavant..
Presentation transcript:

Apache Struts Technology A MVC Framework for Java Web Applications

Agenda Introduction – What is Apache Struts? – Overview of traditional JSP/Servlet web applications The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern – ActionServlet struts-config.xml – Action Classes – ActionForms Validating user input – JSPs and Struts TagLibs – The Model Control flow of a typical request to a Struts application Additional features Summary

Introduction - What is Apache Struts? Struts is an open-source framework for building more flexible, maintainable and structured front-ends in Java web applications There are two key components in a web application: –the data and business logic performed on this data –the presentation of data Struts –helps structuring these components in a Java web app. –controls the flow of the web application, strictly separating these components –unifies the interaction between them This separation between presentation, business logic and control is achieved by implementing the Model-View-Controller (MVC) Design Pattern

Traditional JSP/Servlet Web-Applications Traditionally, there are 3 ways to generate dynamic output (typically HTML or XML) in Java web applications: – Servlets Java classes with some special methods ( doGet(), doPost(), …) Example: out.println(" " + myString + " "); no separation between code and presentation! – JSPs (Java Server Pages) HTML (or other) code with embedded Java code (Scriptlets) compiled to Servlets when used for the first time Example: better, but still no separation between code and presentation! – JSPs with JSTL (JSP Standard Tag Library) JSTL defines a set of tags that can be used within the JSPs There are tags for iterations, using JavaBeans, printing expressions… Example: better readable and thus better maintainability

The Model-View-Controller Pattern - Overview Splits up responsibilities for handling user interactions in an application into three layers: –Model, View, Controller Model – holds application data and business logic – is absolutely independent from the UIs

The Model-View-Controller Pattern - Details View –presentation of parts of the Model to the user –independent from the internal implementation of the Model –there can be different Views presenting the same Model data Controller –“bridge” between Model and View –controls the flow of the application receives/interprets user input performs operations on the Model triggers View update Benefits: –better maintainability and testability of applications –ability to easily develop different kinds of UIs (e.g. console, GUI, …) –separation of different tasks in development –code reusability

Controller ► ActionServlet The central component in a Struts application manages the flow of the application – receives user requests and delegatesthem to the corresponding Action classes – selects the appropriate View to be displayed next (according to ActionForward returned by an Action class) represents a Single Point of Entry of the web application (Front Controller Pattern) implemented as a simple Java Servlet – listed in the deployment descriptor of the surrounding Web Container (usually web.xml) for handling *.do requests can be extended, but in most cases this is not necessary

Controller ► ActionServlet ► struts-config.xml Struts’ main configuration file –used by the ActionServlet defines the control flow, the mapping between components and other global options: – action-mappings – form-beans – forwards – plug-ins –… can be considered a Struts internal deployment descriptor Example: <action path="/login" type="app.LoginAction"> <forward name="failure" path="/login.jsp" /> <forward name="success" path="/welcome.jsp" />

Controller ► Actions perform logic depending on a user’s request Actions – are Java classes that extend Struts’ Action class org.apache.struts.action.Action – The Action's execute() method is called by the ActionServlet Tasks usually performed by Actions: – depending on the type of action: perform the action directly (non-complex actions) call one or more business logic methods in the Model – return an appropriate ActionForward object that tells the ActionServlet which View component it should forward to Ex.: “failure” or “success” in login application

Controller ► ActionForms represent the data stored in HTML forms – hold the state of a form in their properties – provide getter/setter methods to access them – may provide a method to validate form data ActionForms – are Java classes that extend Struts’ ActionForm class org.apache.struts.action.ActionForm – are filled with the form data by the ActionServlet one ActionForm can be used for more than one HTML form – very useful when building wizards or similar types of forms

Controller ► ActionForms ► Validating user input Validation is done – right in the beginning before the data is used by any business methods (at this point, validation is limited to the data structure!) Struts offers two options for server-side validation of user input: – the validate() method in ActionForms can be implemented by the ActionForm developer returns either null (no errors) or an ActionErrors object – a plug-in to use the Jakarta Commons Validator within Struts based on rules defined in an XML file – there can be one or more rules associated with each property in a form – rules can define required fields, min./max. length, range, type error messages and rules can be localized using resource bundles

View ► JSPs with Struts tag libraries The presentation layer in a Struts application is created using standard JSPs together with some Struts Tag Libraries Struts tag libraries – provide access to Model data – enable interaction with ActionForms – provide simple structural logic (such as iteration) –... Example: Username: Password: Login

The Model Holds the data of an application and provides business logic methods Not directly part of the Struts framework! The Model is usually built of different kinds of Business Objects: – JavaBeans simple Java classes, that follow certain naming conventions contain attributes and corresponding getters/setters reside in the Web Container – Enterprise JavaBeans (EJBs) components containing business logic in a J2EE architecture reside in an EJB Container kinds of EJBs: Session Beans, Entity Beans, Message Driven Beans Often a database server is used to make data persistent

Additional Features Tiles (Struts Plug-In) – many different page components can be assembled to a “big” page very useful when having content that is used on many different pages (e.g. sidebars) – defined in XML Internationalization (i18n) – Struts offers some features to easily internationalize an application – Text output can be defined in "resource bundles" that can be provided for many different languages – Struts automatically detects the users language through the HTTP request