• No results found

SSC - Web development Model-View-Controller for Java web application development

N/A
N/A
Protected

Academic year: 2021

Share "SSC - Web development Model-View-Controller for Java web application development"

Copied!
16
0
0

Loading.... (view fulltext now)

Full text

(1)

SSC - Communication and Networking

SSC - Web development

Model-View-Controller for Java web application

development

Shan He

School for Computational Science University of Birmingham

(2)

SSC - Communication and Networking Outline

Outline of Topics

Java Server Pages (JSP)

Model-View-Controller (MVC)

(3)

SSC - Communication and Networking Java Server Pages (JSP)

What is Java Server Pages

I

JSPs: “a Java technology that provides a simplified, fast way

to create easily maintain, information-rich, dynamic Web

pages based on HTML, XML, or other document types.”

I

Viewed as a high-level abstraction of Java servlets: translated

into servlets at runtime from the JSP source file

I

Requires a Servlet container, e.g., Tomcat

I

Life cycle of JSP: very similar to Java Servlet:

I Step 1: JSP Page Translation: Translated as Servlet source code

I Step 2: JSP Page Compilation: Compiled as Servlet class I Other steps are similar to Java Servlet

(4)

SSC - Communication and Networking Java Server Pages (JSP)

What is Java Server Pages

_jspInit() JSP Page (.jsp) _jspService() Servlet class (.class) _jspDestroy()

Finalisation and garbage collection Request Response Servlet container Servlet source (.java) Translate Compile

(5)

SSC - Communication and Networking Java Server Pages (JSP)

How to write JSP

I

Java Code inside HTML using special JSP tags, called JSP

Scriting elements

I

Three categories of JSP Scriting elements:

I Declaration Tags: define varaibales and methods in JSP, start with <%! and end with %> , e.g.,

<%!

String username = Shan; %>

I Expression Tags: produce output (a String object) that can be used to display result on JSP, start with <%= and end with

%> , e.g., <%=name %>

I Scriptlets: start with <% and end with %> , e.g., <%

java.util.Date date = new java.util.Date(); %>

(6)

SSC - Communication and Networking Java Server Pages (JSP)

JSP vs Java Servlet

I

Differences:

I Java Servlet is “HTML in Java”, while JSP is “Java in HTML”.

I Servlets run faster compared to JSP since JSP needs to be translated and compiled before execution.

I More convenient to write JSP to generate HTML

I

Q: When to use JSP?

I

A: When there is not much data process and manipulation,

otherwise use Model-View-Controller design pattern, where

JSP used as View and Servlet as controller

(7)

SSC - Communication and Networking Model-View-Controller (MVC)

Java web application development: problems

I

Many software systems are essentially to retrieve data from a

data store, e.g., a database and display it for the user:

I The user changes the data using an user interface I The system stores the updates in the data store

I

Most straightforward design: combines user interface and data

store to reduce the amount of coding and to improve

application performance

I

Problems:

I user interface tends to change much more frequently than the data storage system.

I mixed up the presentation (the user interface) and application logic (data store).

(8)

SSC - Communication and Networking Model-View-Controller (MVC)

What is Model-View-Controller (MVC)?

I

MVC: a design pattern for efficiently relating the user

interface to underlying data models.

I

Three main components:

I Model: represents the underlying data structures in a software application and the functions to retrieve, insert, and update the data. Note: No information about the user interface. I View: a collection of classes representing the elements in the

user interface for the user to see on the screen

I Controller: classes connecting the model and the view, and is used to communicate between classes in the model and view.

(9)

SSC - Communication and Networking Model-View-Controller (MVC)

What is Model-View-Controller (MVC)?

Model View Controller User Manipulates Request Updates Return results

(10)

SSC - Communication and Networking Model-View-Controller (MVC)

Advantages of MVC

I

Better complexity management:

I Software separate presentation (view) from application logic (model)

I Consequently, code is cleaner and easier to understand I Enable large teams of developers for parallel development

I

Flexibility: Presentation or user interface can be completely

revamped without touching the model

I

Reusability: The same model can used for other application

(11)

SSC - Communication and Networking Model-View-Controller (MVC)

MVC for Java Web Application

I

Model: Plain Old Java Object (POJO) or Java Beans

I

View: Java Server Pages (JSP)

I

Controller: Java Sevlet, which decides:

I what application logic code to be applied in the model I which JSP page is appropriate to present those particular

results and forwards the request there

I

A Java Sevlet Controller:

I handles incoming requests

I instantiates of model and invokes the correct application logic in the model for the request

I forwards the results from the model and request from the user to the appropriate view (JSP file) −→ RequestDispatcher I You can use request.setAttribute or

(12)

SSC - Communication and Networking Model-View-Controller (MVC)

MVC for Java Web Application

Model (POJO/Bean) View (JSP pages) Controller (Servlet) User Instantiate/ invoke Request Forward Request/results Return results

(13)

SSC - Communication and Networking Java Enterprise applications

What is Enterprise applications?

I

Enterprise applications: “ large-scale, multi-tiered, scalable,

reliable, and secure network applications”

I

Three Tier architecture consists of:

I Presentation Tier: usually consists of clients and components that handle the interaction between clients and the application tier

I Application Tier (Business/Logic Tier): coordinates

application, e.g., its business logic, decisions, calculations and evaluations, moves data between the presentation and data tiers.

I Data Tier (Enterprise Information Systems Tier): retrieves and stores data.

(14)

SSC - Communication and Networking Java Enterprise applications

Enterprise applications 3-Tier architecture

Java Enterprise Application Three Tier Architecture

A p p lic ati o n ti er Pr es en ta ti on ti er D ata ti e r

Browser with dynamic

web pages Desktop applications

Servlet/JSP/JSF componets

EJB/POJO

(15)

SSC - Communication and Networking Java Enterprise applications

Tools for Java Enterprise Application Development

I

Java EE: the one your are learning but need learned more

I

Spring Framework: one of the most popular open source

application development framework for developing Java

enterprise applications.

I Consists of many modules to simply development

I The key concept - Inversion of control: the control flow of a program is inverted, e.g., instead the programmer controls the flow of a program, the external source, e.g., Spring Framework takes control of it.

I The fundamental functionality - dependency injection: objects do not create other objects on which they rely to do their work. Instead, they get the objects from by a external framework component.

I The basic idea: to simplify development complexity by loosing couplings/dependencies between classes

(16)

SSC - Communication and Networking Java Enterprise applications

Links

I

Java EE vs Spring

I

Spring Tutorial - Eclipse

I

Spring Tutorial - Netbean

I

Spring guides

References

Related documents

Gainesville State College came to the Athens area in 2003 and draws students from around the state.. The university enrolls 8,883 students and employs 551 full-time

September 2010- current: APTA Online Learning Center: 3 hour CEU course: “Interventions for Stability Aspects of Motor Control: Developmental and neurological disorders across

Enterprise Application Development Using J2EE / © Shmulik London 2004 Interdisciplinary Center Herzeliza Israel Enterprise Application Development using J2EE..

include() method Servlet 1 Servlet 2 Final Response Response Request include Response to be included in Servlet 1 Send to the browser.. SSC - Communication and Networking

Kalandoor Career DMCC Careers Dubai Customs DP World Career Dalkia Dubai Career ADGAS Career Mattex Career [email protected]. Paris Gallery

The purpose of this project was to evaluate if the IBR program at SHZCH improves the patient’s perception of communication with nursing as evidenced by improved patient

Važnost trgovine između država članica EU očituje se u tome da je trgovina robom (izvoz i uvoz zajedno) na unutarnjem tržištu bila veća od trgovine izvan Europske

The local thermal equilibrium implies several assumptions, like low fluid velocities, fast energy exchange between the phases and a smooth spatial temperature distribution.... 2.1