Design Patterns Phil Smith 28 th November 2012. Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.

Slides:



Advertisements
Similar presentations
3 Copyright © 2005, Oracle. All rights reserved. Designing J2EE Applications.
Advertisements

Apache Struts Technology
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
DT211/3 Internet Application Development JSP: Processing User input.
Introduction to Web Application Architectures Web Application Architectures 18 th March 2005 Bogdan L. Vrusias
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
Structure of a web application1 Dr Jim Briggs. MVC Structure of a web application2.
Apache Struts Technology A MVC Framework for Java Web Applications.
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.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
ABSTRACT Zirous Inc. is a growing company and they need a new way to track who their employees working on various different projects. To solve the issue.
CIS 285 ROBINSON WINTER 2005 CIS 285 Web Application Development with Java CIS 285 Sinclair Community College Instructor: Mary Robinson.
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Standalone Java Application vs. Java Web Application
CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags.
® IBM Software Group © 2007 IBM Corporation J2EE Web Component Introduction
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
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–
Fall CIS 764 Database Systems Design L8. Web ….
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
3-Tier Web Application Architecture. Simple Log-in public String button1_action() { // TODO: Process the button click action. Return value is a navigation.
MVC Model 2 Architecture & AddressBook case study
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Model View Controller Architecture of Java Web Applications Dr. M V S Peri Sastry, Ph.D.[BITS-Pilani]
Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.
CourseOutline Example & JavaBeans Lec Start with Example Displaying Course Outlines User will select either course “web design & development” or.
Servlet Filters JAVA Enterprise Edition. Servlet Filters Servlet Filters are Java classes that can be used in Servlet Programming for the following purposes:
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© 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.
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.
Team Members Tyler Lamb Kirk Olson James Woestman IRP Presentation Client Zirous Inc. Faculty Advisor Tien Nguyen 1.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
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.
Apache Struts Technology A MVC Framework for Java Web Applications.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Structure of a web application
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Scripted Page Web App Development (Java Server Pages)
Knowledge Byte In this section, you will learn about:
Design and Maintenance of Web Applications in J2EE
Introduction to Struts
Lecture 1: Multi-tier Architecture Overview
The Model Layer What is Model?
Struts BY: Tejashri Udavant..
Presentation transcript:

Design Patterns Phil Smith 28 th November 2012

Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the bad (and the ugly) is important.

Why should we use design patterns? Reduces Development Time Reduced Maintenance Time Collaboration Importance grows with the size of a project Rebuilding an app is never desirable Good design ensures an app should never need a complete overhaul

Common Design Patterns Numerous ways to classify design patterns Concepts important, not names Design patterns do not date like code Important to logically separate an app's functionality

Model 1 Concept: Code functionality wherever the functionality is needed Simple Instant Gratification Need security? Code it in. Need to access a DB? Code it in. Relies on a request going to one resource, and the resource returning the correct reply

Illustration of Model 1 Architecture

Index.jsp Responsible for displaying all current news No forms Scripting elements present These are used to load and read information about current news News is saved in an XML file, news.xml

index.jsp

Addnews.jsp Includes scripting elements Method to solicit information from user HTML form

Addnews.jsp

Header.jsp

Why is this Model 1? Each request being mapped to a single endpoint The endpoint is solely responsible for generating the final response This application directly follows this rule Each request URL goes to exactly one resource in the app. All the response-generating logic is in the same resource

3 General Types of Page Static page Easily authored in HTML Page doesn't change Dynamic page Relies on server-side functionality provided by Servlets and JSP Dynamic form page Requires user participation Usually through HTML form

Types of page Static pages are used in all design patterns They are easy to author Dynamic pages are where different design patterns are important Where the logic is placed can impact the ease of use

Model 1 Weaknesses No great strengths Used for trivial apps Can be used by inexperienced developers Design limits development of dynamic pages Makes dynamic pages overly complex and cryptic Difficult to maintain; hard to edit Dynamic code alongside formatting

Weaknesses contd. Index.jsp and Addnews.jsp hard to understand Scripting elements especially Java developers allowed to haphazardly embed code where they please No separation of data access code and response generating code Addnews.jsp should be two separate pages Separated by conditional statement

Weaknesses contd. Combining pages is a bad idea Turns simple pages into one complex one Code harder to manage Attempts to modify code may break it Combined pages are common to Model 1 Especially when forms are involved Validation of forms Flaws due to JSP scripting elements

Model 2 Also called Model View Control (MVC) Seeks to solve problems of Model 1 Best method of implementing apps using Servlets and JSP Popuplarized by Struts Framework Separates business logic from presentation logic

Logic Business Logic Consists of everything required to get needed runtime information Presentation logic Consists of everything needed to format the information into a form a client expects Separation keeps both parts simple Both are more easily manipulated

MVC Model Representation of the app's data repository Code involved with reading, writing and validation View Interacts with user Control Links the previous two components Responsible for providing proper view to user Keeps Model current

Implementation of Model 2 View Solely done via JSP Model Encapsulated as a set of JavaBeans Manipulated with JSP Control Servlet or Filter

JavaBean Is a standard class for holding data: All its fields are private Fields are only accessible through getter and setter methods It has a constructore that takes no arguments It is Serializable

Filter Performs filtering tasks on either: A servlet's request A servlet's response Both Filtering performed through the doFilter method Used for: Authentication Logging Image conversion Data compression Encryption

Model 2 Architecture

Important Concepts Everything is cleanly separated Layers the different types of functionality Interfaces that the different parts of the design use to communicate JavaBeans used by the view Implementation of Control component Servlet accepts all requests and responses Very convenient to implement security, logging

Rebuilding the news site New classes Filter is used as the Control component A Java bean is required to communicate with the JSP View pages Filter is designed to intercept all request Also executes implicit Java classes that are assumed to contain Model 2 logic

ControlFilter.java

If index.jsp is requested, Filter checks to see if it exists If so, ControlFilter has a chance to process the request and response before index.jsp However, Java objects are not inherently designed to do this So, we need an interface.

Control.java

Model 1 to Model 2 We must attempt to remove all scripts Script's logic needs to be built into a logic component for use with the Control Filter Index.jsp is the web page Index.java is it's implicit logic component

Index.java

Index.jsp using JSTL

Web.xml for Control Filter

Why is this Model 2? Enforcement of separation of business logic from presentation Filter acts as controller When request received, Filter initializes an appropriate model Then forwards control to the view View JSP extracts data from the model Uses it to create the presentation data, the HTML

Why is this Model 2? At no point is business logic mixed with presentation No scripting elements No HTML produced by Filter View contains only HTML markup and dynamic data Model and Control abstract out all code responsible for generation of dynamic data

Model 2 Strengths Clean separation of business logic and presentation Pages are clean and elegant Maintenance is simple

Model 2 Strengths View has no idea where information comes from, but it does not matter It could be a database, flat file or anything else. Underlying data can be freely changed, depending on the contents of the Servlet There is a good level of abstraction between the View and Model This is as long as the request-scope variables between the two are correctly used

Model 2 Strengths Control perfect to manipulate all requests and responses Convenient for security, logging and error handling OO-programming concepts that Java is built upon

Model 2 Weaknesses None!