J2EE Lecture 7: Spring – Spring MVC

Slides:



Advertisements
Similar presentations
Spring 3.0 MVC - Introduction By, Srinivas Reddy.S
Advertisements

1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Beginning Spring MVC Spencer Uresk. Notes This is a training, NOT a presentation Please ask questions This is being recorded
Spring MVC Part 2 Spencer Uresk. Notes This is a training, NOT a presentation Please ask questions This is being recorded
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
Spring MVC form handling annotation example
ASP.NET Programming with C# and SQL Server First Edition
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Spring Framework Benefits…
UNIT-V The MVC architecture and Struts Framework.
ASHIMA KALRA.  INTRODUCTION TO JSP INTRODUCTION TO JSP  IMPLICIT OBJECTS IMPLICIT OBJECTS  COOKIES COOKIES.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Separation of Concerns Technion – Institute of Technology Author: Gal Lalouche - Technion 2015 © 1.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
JSP Java Server Pages Softsmith Infotech.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
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
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
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.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
16-Oct-15 JSP Implicit Objects. 2 JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer.
Opus College – Techniques Spring Annotated Controllers.
Chapter 6 Server-side Programming: Java Servlets
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Forms with Spring MVC Handling Form.
INTEGRATION OF BACKBONE.JS WITH SPRING 3.1. Agenda New Features and Enhancements in Spring 3.1 What is Backbone.js and why I should use it Spring 3.1.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
1 Web Programming with Servlets & JSP ASSIGNMENT GUIDELINE.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
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.
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Annotation-Based Spring Portlet MVC John A. Lewis Chief Software Architect Unicon, Inc. Jasig 2010 Conference 8 March 2010 © Copyright Unicon, Inc., 2010.
Data and tools on the Web have been exposed in a RESTful manner. Taverna provides a custom processor for accessing such services.
3 Introduction to Classes and Objects.
Web Programming Developing Web Applications including Servlets, and Web Services using NetBeans 6.5 with GlassFish.V3.
Section 13 - Integrating with Third Party Tools
Developing JavaServer Pages
Play Framework: Introduction
Delegates and Events 14: Delegates and Events
Pre assessment Questions
Pre-assessment Questions
MVC Framework, in general.
WEB API.
Lecture 22 Inheritance Richard Gesick.
CS5220 Advanced Topics in Web Programming Spring – Web MVC
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Lecture 5: Functions and Parameters
J2EE Lecture 1:Servlet and JSP
J2EE Lecture 13: JMS and WebSocket
JavaScript: Introduction to Scripting
Pre-assessment Questions
Presentation transcript:

J2EE Lecture 7: Spring – Spring MVC Dr. Ming Qiu Xiamen University Software School mingqiu@xmu.edu.cn

Reference 1 7.1 What is Spring MVC The request processing workflow

7.1 What is Spring MVC The life cycle of a request in Spring MVC Reference 1 7.1 What is Spring MVC The life cycle of a request in Spring MVC

7.1 What is Spring MVC

7.1 What is Spring MVC

7.1 What is Spring MVC

Spring in Action, Chap 8 7.2 DispatcherServlet

7.2 DispatcherServlet Typical context hierarchy in Spring Web MVC Reference 1 7.2 DispatcherServlet Typical context hierarchy in Spring Web MVC Spring MVC looks for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application

7.2 DispatcherServlet Single root context in Spring Web MVC Reference 1 7.2 DispatcherServlet Single root context in Spring Web MVC

Reference 1 7.2 DispatcherServlet

Reference 1 7.3 Controller Controllers interpret user input and transform it into a model that is represented to the user by the view

Reference 1 7.3 Controller Autodetection of controllers

Reference 1 7.3 Controller @RequestMapping

Reference 1 7.3 Controller

7.3 Controller Supported method return types Reference 1 7.3 Controller Supported method return types A ModelAndView object, with the model implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods. A Model object, with the view name implicitly determined through a RequestToViewNameTranslator and the model implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods.

Reference 1 7.3 Controller A Map object for exposing a model, with the view name implicitly determined through a RequestToViewNameTranslator and the model implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods. A View object, with the model implicitly determined through command objects and @ModelAttribute annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a Model argument (see above).

Reference 1 7.3 Controller A String value that is interpreted as the logical view name, with the model implicitly determined through command objects and @ModelAttribute annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a Model argument (see above). void if the method handles the response itself or if the view name is supposed to be implicitly determined through a RequestToViewNameTranslator (not declaring a response argument in the handler method signature).

Reference 1 7.3 Controller If the method is annotated with @ResponseBody, the return type is written to the response HTTP body. The return value will be converted to the declared method argument type using HttpMessageConverters. See the section called “Mapping the response body with the @ResponseBody annotation”. An HttpEntity<?> or ResponseEntity<?> object to provide access to the Servlet response HTTP headers and contents. The entity body will be converted to the response stream using HttpMessageConverters. See the section called “Using HttpEntity”.

7.3 Controller Supported method return types Reference 1 7.3 Controller Supported method return types An HttpHeaders object to return a response with no body. A Callable<?> can be returned when the application wants to produce the return value asynchronously in a thread managed by Spring MVC. A DeferredResult<?> can be returned when the application wants to produce the return value from a thread of its own choosing.

Reference 1 7.3 Controller A ListenableFuture<?> can be returned when the application wants to produce the return value from a thread of its own choosing. A ResponseBodyEmitter can be returned to write multiple objects to the response asynchronously; also supported as the body within a ResponseEntity. An SseEmitter can be returned to write Server-Sent Events to the response asynchronously; also supported as the body within a ResponseEntity.

Reference 1 7.3 Controller A StreamingResponseBody can be returned to write to the response OutputStream asynchronously; also supported as the body within a ResponseEntity. Any other return type is considered to be a single model attribute to be exposed to the view, using the attribute name specified through @ModelAttribute at the method level (or the default attribute name based on the return type class name). The model is implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods

7.3 Controller Introduce ModelAndView fully encapsulates the view and model data that is to be displayed by the view.

7.3 Controller @RequestParam Reference 1 7.3 Controller @RequestParam bind request parameters to a method parameter in your controller.

Reference 1 7.3 Controller

7.3 Controller @ResponseBody Reference 1 7.3 Controller @ResponseBody be put on a method and indicates that the return type should be written straight to the HTTP response body not placed in a Model, or interpreted as a view name

7.3 Controller HttpEntity and ResponseEntity Reference 1 7.3 Controller HttpEntity and ResponseEntity access to the request and response body, access to the request and response headers

7.3 Controller Use @ModelAttribute on a method Reference 1 7.3 Controller Use @ModelAttribute on a method the purpose of that method is to add one or more model attributes

7.3 Controller Using @ModelAttribute on a method argument Reference 1 7.3 Controller Using @ModelAttribute on a method argument indicates the argument should be retrieved from the model. If not present in the model, the argument should be instantiated first and then added to the model. Once present in the model, the argument’s fields should be populated from all request parameters that have matching names

Reference 1 7.3 Controller There are several options that the Pet instance come from It may already be in the model due to use of @SessionAttributes  It may already be in the model due to an @ModelAttribute method in the same controller. It may be retrieved based on a URI template variable and type converter. It may be instantiated using its default constructor.

Reference 1 7.3 Controller the name of the model attribute (i.e. "account") matches the name of a URI template variable

Reference 1 7.3 Controller Using @SessionAttributes to store model attributes in the HTTP session between requests

7.3 Controller Mapping cookie values with the @CookieValue annotation Reference 1 7.3 Controller Mapping cookie values with the @CookieValue annotation

Reference 1 7.3 Controller Mapping request header attributes with the @RequestHeader annotation

7.3 Controller Method Parameters And Type Conversion Reference 1 7.3 Controller Method Parameters And Type Conversion Spring automatically converts to the appropriate type. All simple types such as int, long, Date, etc. are supported Can further customize the conversion process through a WebDataBinder or by registering Formatters with the FormattingConversionService

Reference 1 7.4 Resolving views Enable you to render models in a browser without tying you to a specific view technology. Out of the box, Spring enables you to use JSPs, Velocity templates and XSLT views,

Reference 1 7.4 Resolving views with JSP as a view technology, you can use the UrlBasedViewResolver. This view resolver translates a view name to a URL and hands the request over to the RequestDispatcher to render the view.

7.5 Spring’s multipart (file upload) support Reference 1 7.5 Spring’s multipart (file upload) support Using a MultipartResolver with Commons FileUpload

7.5 Spring’s multipart (file upload) support Reference 1 7.5 Spring’s multipart (file upload) support Handling a file upload in a form

7.5 Spring’s multipart (file upload) support Reference 1 7.5 Spring’s multipart (file upload) support

Reference Spring Framework Reference Documentation. http://docs.spring.io/spring/docs/4.2.3.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/