CS5220 Advanced Topics in Web Programming Spring – Web MVC

Slides:



Advertisements
Similar presentations
Persistence Jim Briggs 1. 2 Database connectivity: JDBC Java Database Connectivity An API for connecting Java programs (applications, applets and servlets)
Advertisements

Apache Struts Technology
Beginning Spring MVC Spencer Uresk. Notes This is a training, NOT a presentation Please ask questions This is being recorded
An Introduction To the Spring M.V.C. Framework Reference From Website By Tom Kochanowicz.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
© Internna Technologies 1 IWebMvc Features, Possibilities & Goals.
Address - #22, 1 st Floor, Station View Road, Kodambakkam, Chennai JTech Soft Solutions Website:
Spring Framework Benefits…
UNIT-V The MVC architecture and Struts Framework.
Spring Roo CS476 Aleksey Bukin Peter Lew. What is Roo? Productivity tool Allows for easy creation of Enterprise Java applications Runs alongside existing.
Separation of Concerns Technion – Institute of Technology Author: Gal Lalouche - Technion 2015 © 1.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
OpusCollege and the use of Spring and iBatis
Standalone Java Application vs. Java Web Application
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 ….
Opus College – Techniques Spring Annotated Controllers.
1 Apache TomEE // JavaEE Web Profile on Tomcat Jonathan #TomEE.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
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.
Getting started with ASP.NET MVC Dhananjay
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Dependency Injection JAVA EE - Spring Framework. Inner Beans As you know Java inner classes are defined within the scope of other classes, similarly,
Chapter 9 Web Application Design. Objectives Describe the MVC design pattern as used with Web applications Explain the role and responsibilities of each.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
Apache Struts Technology A MVC Framework for Java Web Applications.
DSPACE UI Challange Roberto Suardi – Luigi Andrea Pascarelli
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Bits and Pieces of Web Programming (II) Chengyu Sun California State University, Los Angeles.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
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)
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
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.
CS520 Web Programming Spring – Inversion of Control Chengyu Sun California State University, Los Angeles.
Open Software Integrators, LLC 1 Spring Roo - IDE Research ● Basics of Spring Roo (Installation and Roo shell) ● Spring Roo, Maven, Tomcat works! ● Front.
Annotation-Based Spring Portlet MVC John A. Lewis Chief Software Architect Unicon, Inc. Jasig 2010 Conference 8 March 2010 © Copyright Unicon, Inc., 2010.
Jim Fawcett CSE686 – Internet Programming Spring 2014
CS3220 Web and Internet Programming Database Access with JDBC
Chengyu Sun California State University, Los Angeles
CS520 Web Programming Declarative Security (II)
Jim Fawcett CSE686 – Internet Programming Spring 2012
CS520 Web Programming Bits and Pieces of Web Programming (II)
CS320 Web and Internet Programming Database Access with JDBC
A very brief introduction
CS520 Web Programming Spring – Inversion of Control
J2EE Lecture 7: Spring – Spring MVC
CS320 Web and Internet Programming Cookies and Session Tracking
The Model Layer What is Model?
CS320 Web and Internet Programming MVC Architecture
CS3220 Web and Internet Programming Cookies and Session Tracking
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming Cookies and Session Tracking
CS5220 Advanced Topics in Web Programming Secure REST API
CS4961 Software Design Laboratory Understand Aquila Backend
Rules and Tips for Good Web Programming (and Programming in General)
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Presentation transcript:

CS5220 Advanced Topics in Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles

Spring Framework

The SpringMVC Example Spring and Hibernate from Scratch http://csns.calstatela.edu/wiki/content/cysun/course_materials/cs520/sham/

Add Spring MVC to A Maven Webapp Spring dependencies spring-webmvc Front controller DispatcherServlet in web.xml Bean configuration file /WEB-INF/<servlet-name>-servlet.xml

Request Processing in Spring Web MVC Controller URL Mapping Controller URL Mapping Controller Request Front Controller Controller Application Server model Response View Resolution View

Spring Controllers Spring controllers are beans annotated with @Controller In <servlet-name>-servlet.xml <mvc:annotation-driven> <context:component-scan>

Controller URL Mapping Requests are mapped to controller methods using @RequestMapping value: URL pattern(s) Mapping can be further refined by using method, params, and headers https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-requestmapping

View A controller method returns a view name, which will be resolved to a view implementation by a view resolver

Resolve JSP Views Prefix + ViewName + Suffix = JSP File <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix“ value=".jsp" /> </bean> Prefix + ViewName + Suffix = JSP File Why not just return the path to the JSP file??

View Technologies and Resolvers https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-view

Model Model objects are passed to view using a ModelMap put( String, Object ) attribute name attribute value

Request Processing Recap 3 Controller URL Mapping Controller 1 URL Mapping 2 Controller Request Front Controller Controller 4 Application Server 5 model Response View Resolution 6 View 7

Database Access Dependencies Hibernate Spring ORM Database connection pooling DBCP vs. Tomcat JDBC Database driver

Configuration Hibernate JPA Spring persistence.xml web.xml applicationContext.xml

Spring Transaction Management Transaction management code is added through AOP <context:annotation-config> enables annotations like @Autowired and @PersistenceContext <tx:annotation-driven> enables annotations like @Transactional

Model Classes and Database Model classes, e.g. User JPA annotations Database SQL scripts hibernate_sequence

Database Access DAO interfaces, e.g. UserDao DAO implementations, e.g. UserDaoImpl

Spring DAO Annotations @Repository for DAO implementation classes @PersistenceContext injects an entity manager to the class @Transactional for methods that write to the database

Controller Examples List all users Display a selected user Add a new user Edit a user

Example: List All Users Controller basics @Controller @RequestMapping @ModelMap Using DAO

Example: Display A User Using @RequestParam required Using @PathVariable

Access HTTP Request, Response, and Session Simply add an argument of that type to the controller method https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-methods

Example: Add A User Model attribute (a.k.a. command object, form backing object, form object) Concept Binding @ModelAttribute @RequestMapping method The “redirect” view

Model Attribute HTML Form model attribute Binding public class User { String username; String password; … } Usename: Password: Login Bind form fields to properties of the object

Spring’s form Tag Library Documentation –https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-view-jsp-formtaglib Tag reference – https://docs.spring.io/spring/docs/4.3.x/spring-framework-reference/html/spring-form-tld.html

Handling Forms One controller method for Form view Creating a model attribute Returning the form view Form view Use Spring <form> tags to bind the model attribute to the form Processing the model attribute (annotated with @ModelAttribute) Returning the success view

Example: Edit A User Store model attribute in session @SessionAttributes SessionStatus Use setComplete() to remove the model attribute in session

Non-Session Model Attributes Form request Form Submission Create a model attribute in controller Create a model attribute Populate the model attribute with submitted data Use the model attribute to populate the form fields in view Pass the model attribute to controller

Session Model Attributes Form request Form Submission Create a model attribute in controller Retrieve the model attribute from session Populate the model attribute with submitted data Save the model attribute in session Use the model attribute to populate the form fields in view Pass the model attribute to controller

Readings Spring Framework Documentation – Web Servlet Chapter 1. Spring Web MVC