Separation of Concerns Technion – Institute of Technology 236700 Author: Gal Lalouche - Technion 2015 © 1.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Apache Struts Technology
Servlets Enterprise Systems Programming. Servlets  Servlets: server-side Java programs that enable dynamic processing of web-based requests  Web-based.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
Apache Struts Technology A MVC Framework for Java Web Applications.
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.
Web Application Architecture: multi-tier (2-tier, 3-tier) & mvc
Struts 2.0 an Overview ( )
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.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Ruby on Rails. What is Ruby on Rails? Ruby on Rails is an open source full-stack web framework. It is an alternative to PHP/MySQL. It can render templates,
J2EE Web Fundamentals Lesson 1 Introduction and Overview
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
SDPL 2002Notes 7: Apache Cocoon1 7 XML Web Site Architecture Example: Apache Cocoon, a Web publishing architecture based on XML technology
Java Omar Rana University of South Asia. Course Overview JAVA  C/C++ and JAVA Comparison  OOP in JAVA  Exception Handling  Streams  Graphics User.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
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.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
Java CGI Lecture notes by Theodoros Anagnostopoulos.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
SDPL 2001Notes 7.2: Apache Cocoon1 7.2 Apache Cocoon An example of a Web publishing architecture based on XML technology An.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
Chapter 6 Server-side Programming: Java Servlets
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
INTRODUCTION TO WEB APPLICATION Chapter 1. In this chapter, you will learn about:  The evolution of the Internet  The beginning of the World Wide Web,
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.
2007cs Servers on the Web. The World-Wide Web 2007 cs CSS JS HTML Server Browser JS CSS HTML Transfer of resources using HTTP.
Martin Kruliš by Martin Kruliš (v1.1)1.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
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.
Dependency Injection Frameworks Technion – Institute of Technology Author: Assaf Israel - Technion 2013 ©
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
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.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
JSP / Servlets and Beans
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
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.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Intro To MVC Architecture.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Model Viewer Controller Technion – Institute of Technology Author: Gal Lalouche - Technion 2015 © 1.
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.
MVC Architecture, Symfony Framework for PHP Web Apps
J2EE Lecture 7: Spring – Spring MVC
Haritha Dasari Josue Balandrano Coronel -
Design and Maintenance of Web Applications in J2EE
Lecture 1: Multi-tier Architecture Overview
Introduction to Servlets
CS4961 Software Design Laboratory Understand Aquila Backend
#01# ASP.NET Core Overview Design by: TEDU Trainer: Bach Ngoc Toan
Web Application Development Using PHP
Presentation transcript:

Separation of Concerns Technion – Institute of Technology Author: Gal Lalouche - Technion 2015 © 1

What are concerns? Big applications are consisted of many components/modules A single feature usually involves several steps, that includes several components that interact with each other It is easier to write and maintain a program where each module has a defined set of responsibilities and that the "glue" between these components is minimal Code is modular and reusable Author: Assaf Israel - Technion 2013 © 2

Test case – Web applications A typical web app architecture Author: Assaf Israel - Technion 2013 © 3 HTTP Request Get: /myApp/employee_details?username=don&passwd=12345 myApp Get : employee_details Param#1 = username, value = don Param#2 = passwd, value = HTTP Response Employee Logic Prepare Response Login page … Client Welcome back Mr’ Quixote … Databases Get Employee data Author: Gal Lalouche - Technion 2015 © 3 Web Server (Apache, Tomcat, etc.)

Servlets We’ll write Java classes named Servlets extending the HttpServlet class Each class will be mapped to a URL and a method in it will be invoked when an HTTP request is made to that URL Author: Assaf Israel - Technion 2013 © 4

Servlets (cont.) Problem: Writing HTML in Java is hard Solution: Write Java in HTML Author: Assaf Israel - Technion 2013 © 5

Servlets (cont.) Behind the scenes Tomcat will: Process the JSP code and will create a Servlet Java code Then compile and run it You can see the generated.java servlet files in /work/… folder You can learn more in the course: Managing Data on the World-Wide Web Managing Data on the World-Wide Web Author: Assaf Israel - Technion 2013 © 6

Domain Specific Languages (DSL) JSP is an example for External DSL ‘External’ means it is not written as part of the hosted language In our case, Java is written HTML Last week, we wrote SQL and HQL inside Java DSL’s purpose is making our lives easier by: Allowing us to write less code Code is simpler and easier to read Force us into good coding practices We can also write our own Internal DSL For most generic purposes, someone already wrote something better… Author: Assaf Israel - Technion 2013 © 7

Typical Servlet Code What’s the problems with the web development approaches we’ve seen so far? Author: Assaf Israel - Technion 2013 © 8

Client-Server coupling Servlet need to know the format of the answer (HTML/JSON/XML) Parameters are resolved within the Servlet Type resolution: strings, integers, classes Value: age, name, id As a result most of the Servlet code is handling "bureaucracy" which opens the door for bugs and consume a lot of development time Hard to decouple the UI (HTML/JSP) code from the data handling and logic. In short, servlets do Everything Author: Assaf Israel - Technion 2013 © 9

Model-View-Controller Ubiquitous architectural design pattern… A logical concerns separation to 3 parts: Model: Data representation & manipulation View: Graphical presentation / UI Controller: Business Logic Goals: Independent development of each cocern Sometimes by completely different professions Reusability and modularity Simpler, shorter code Ignorance is bliss Most importantly, a framework methodology/structure Author: Assaf Israel - Technion 2013 © 10

Model-View-Controller

MVC with Spring A framework for Java based Web development Eclipse integration We’ll only cover a fraction of this package’s features You may find more videos/tutorials online and in the course website. It’s a “first-generation” MVC framework Next week we will see a newer framework, called Play Author: Assaf Israel - Technion 2013 © 12

Spring programming model

The new Servlet The DispatcherServlet will redirect incoming requests to annotation used to define mapping rules Method parameters used to obtain request input Method return values used to generate responses Simplest Author: Assaf Israel - Technion 2013 © 14

Mapping Requests By By HTTP od.GET) POST,PUT,DELETE,OPTIONS and TRACE are also supported By presence of query Negation also supported: params={"foo","!bar"} By presence of request type=text/*") Negation also supported Author: Assaf Israel - Technion 2013 © 15

Request mapping at class can be used at the class level Concise way to map all requests within a path to Author: Assaf Israel - Technion 2013 © 16

Obtaining request data Previously we needed to investigate the HttpServletRequest object for parameters Say we want to add a new Employee to our online DB

Obtaining request data, take II

Obtaining request data, take III But why not just use Employee as the method parameter? Spring can convert request parameters to all of Java’s simple types, as well as a few basic types (String, Arrays, Date, etc.) and to Java beans You can get request data from URL/headers/cookies/request body

Java Beans A Java bean is a Java class with getters & setters for some of its private members Spring will find name and age in the request parameters and will match them to the Employee bean by their name. More complex data conversions are possible via custom Resolvers. These will be injected when needed Note that beans are mutable by definition

Generating responses Can return a POJO annotated Will be returned as the body of the response Automatic conversions to client’s expected format (JSON,XML,…) Return a new ResponseEntity object More powerful; allows setting custom headers and status code

Returning a View In order for the controller to avoid messing with the view code, it is custom to simply pass on control to a designated view. The view can be any static or dynamic created content. Will redirect to successAdd.jsp

Model processing The Model is a simple data container. should prepare the Model for the specific action and pass it on to the View to be rendered accordingly

Model processing SuccessAdd.jsp code: Try doing this using standard methods and you’ll need: cookies/sessions/static variables…

Views Which one do I use? Use views to generate documents for display in a web browser: HTML, PDF, etc. to exchange data with web service clients (e.g. JS AJAX): JSON, XML, etc. Author: Assaf Israel - Technion 2013 © 25

Not exclusive to Java C# Razor / ASP.NET Python Django Ruby Ruby on Rails Scala / Java Play Framework (we will see next week) Author: Assaf Israel - Technion 2013 © 26

Only scratched the surface… Haven’t covered today: Type conversion Validation FTP services Exception handling Load balancing Reference Manual Show case video Author: Assaf Israel - Technion 2013 © 27