Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding MVC Architecture & Apache Struts in Web Dev, Study notes of Computers and Information technologies

An introduction to the model-view-controller (mvc) architecture and the apache struts framework in the context of web-based commerce. Mvc is an architectural pattern that separates the presentation, application logic, and resource management layers, while apache struts is an open-source framework for creating java web applications. The basics of mvc, its implementation in various frameworks, and the role of apache struts in mvc-based web development.

Typology: Study notes

2010/2011

Uploaded on 09/09/2011

asdlol2
asdlol2 🇬🇧

4.4

(8)

233 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Web Based Commerce 514H3
Dr Kingsley Sage
Room 2R308, Chichester II
khs20@sussex.ac.uk
© University of Sussex 2007
Lecture 2
The Model View Controller (MVC) architecture
Introducing the Struts framework
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Understanding MVC Architecture & Apache Struts in Web Dev and more Study notes Computers and Information technologies in PDF only on Docsity!

Web Based Commerce 514H

Dr Kingsley Sage Room 2R308, Chichester II khs20@sussex.ac.uk © University of Sussex 2007

Lecture 2

 The Model View Controller (MVC) architecture  Introducing the Struts framework

From lecture 1 …

 Design patterns

  • Describes a problem which occurs over and over again and then describes the core of the solution to that problem, in such a way that you can use the solution many times over”
  • “Patterns are optimal solutions to common problems. As common problems are tossed around a community and are resolved, common solutions often emerge. Eventually the best of these rise above the din and become refined until they reach the status of a Design Pattern”

Design patterns

 Design patterns

  • Proven: you tape the knowledge and insight of other developers
  • Reusable: You don’t have to invent a new solution; you follow the pattern and adapt it as necessary
  • Expressive: provide a common vocabulary for solutions
  • But, do not guarantee success!!  Model View Controller (MVC) first defined by the Smalltalk programming language in the 1970s
  • MVC idiom has become commonplace, especially in object orientated systems

MVC

 Model: The domain specific representation on which the application operates  View: Renders the model into a form suitable for interaction, typically a user interface. MVC is often seen in web applications, where View is the HTML page and the code which gathers dynamic data for the page  Controller: Processes and responds to events, typically user actions and may invoke changes on the Model and View

MVC – typical control flow

  1. User interacts with the user interface in some way (e.g. presses a button)
  2. A controller handles the input event from the user interface
  3. Controller accesses the Model, possibly updating it in a way appropriate to the user’s action (e.g. controller updates the user’s shopping cart)
  4. View uses the Model to generate an appropriate user interface. The Model gets its own data from the model. The Model has no direct knowledge of the View
  5. User interface waits for further interactions

MVC – implementations

 MVC has inspired many frameworks, including:

  • Java Swing
  • Qt Toolkit
  • Xforms
  • ASP.NET  Remember, MVC is not a codebase, or a container, it’s just a design pattern

MVC – ASP.NET overview

 In ASP.NET the patterns for the View and Controller are well defined. The Model is left to the developer to design

  • View: The ASPX and ASCX files handle the view. The View object actually inherits its structure and methods from the Controller object. This is different to the Smalltalk scheme, where separate classes have pointers to one another
  • Controller: Generation and passing of events is handled by the .NET framework (Page and Control classes)
  • Model: .NET does not strictly require a Model. Can forego Model class and have event handlers in the Controller perform calculations (nicer to have a proper Model though).

Apache Struts - overview

 Struts can be considered an industrial strength framework suitable for large applications, but not yet a standard  Main attraction is that developers can make use of configurable application components (e.g. Controller servlet) that come with the distribution  Whole application held together with XML configuration file called struts-config.xml (stored in the app’s WEB-INF directory)

Apache Struts and JSP

 Struts provides a robust infrastructure for Model 2 application development using the Front Controller and Service-To-Worker design patterns  View portion is most often constructed using Java Server Pages. JSP can contain static HTML text, plus the ability to insert dynamic content based on the run time interpretation of special action tags. There is a set of standard tags and you can add your own tags in custom tag libraries

Apache Struts - Controller

 Struts provides the Controller part of the application. Controller receives requests from the user, decides what business logic needs to be performed and then delegates responsibility for producing the next phase of the user interface to an appropriate View component  Primary component is a servlet of class ActionServlet  Servlet is configured by defining ActionMappings  ActionMapping defines a path matched against the request URI and specifies fully qualified class name of an Action class  All Actions sub-classed from org.apache.struts.action.Action

Apache Struts – control flow

 Typical control flow:

  • When initialised, the controller parses a configuration file and uses it to deploy other control layer objects. The configuration defines (among other things) the ActionMappings
  • The controller components consults the ActionMappings as it routes HTTP requests to other components in the framework. Requests may be forwarded to JSP’s or Action subclasses provided by the application developer

OK – so let’s see an example

 Taken from www.allapplabs.com/struts/

Lab sheet 1 (week 2)

 Lab sheet 1 is a short programming exercise working with the Struts framework  You do not need to become a Struts expert – you will be likely using some of it in coursework 2  It’s just to get you used to the ideas of a framework and the functionality they provide in the context of a well regarded product  See the course web site for the lab sheet

Next time …

 Transaction processing  Databases for back end systems  MySQL  Using Java Data Base Connectivity (JDBC)