1 / 19

CS520 Web Programming Introduction to MVC and Web Application Frameworks

CS520 Web Programming Introduction to MVC and Web Application Frameworks. Chengyu Sun California State University, Los Angeles. Example – Items (JSP version). Login.jsp authentication. No session attribute admin. No session attribute user. set session attribute admin. set session

Download Presentation

CS520 Web Programming Introduction to MVC and Web Application Frameworks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS520 Web ProgrammingIntroduction to MVC and Web Application Frameworks Chengyu Sun California State University, Los Angeles

  2. Example – Items (JSP version) • Login.jsp • authentication No session attribute admin No session attribute user set session attribute admin set session attribute user • Admin.jsp • display items • adding new items • User.jsp • display items logout logout • Logout.jsp • invalidate session

  3. About Items (JSP version) • Advantages • Easy to code • Problems • ??

  4. Model 1 Architecture • JSPs + Java beans • JSPs for presentation • beans for business logic JSP 3 JSP 1 JSP 4 JSP 2

  5. Java Beans • POJO (Plain Old Java Objects) • Properties defined by getter and setter methods

  6. Items (Model 1 version) • What would it look like?? • Compared to the JSP version, what problems are addressed and what still remain??

  7. Model 2 Architecture • Also know as Model-View-Controler (MVC) architecture • JSPs + beans + servlet • Beans for business logic – Model • JSPs for presentations – View • servlet for web logic – Controller • HTTP related processing, e.g. request, response, sessions etc. • Request dispatching

  8. MVC Control Flow ... model 2 3 controller 1 4 user view 5

  9. ... MVC Control Flow • Process request • Populate beans • Store results in request, session, or servlet context • Forward request to JSP page • Extract bean data from beans and display

  10. Multiple Controllers Front Controller … … Controller Controller Controller … … view model view model

  11. Items (MVC version) • FrontController • Login handler • Logout handler • User handler • Admin handler • Models: Item and User • Views: Login.jsp, Admin.jsp, User.jsp

  12. Admin Control Flow 1. Process request 2. Populate beans List<Item> items = itemDao.getAllItems(); 3. Store results in request, session, or servlet context request.setAttribute( "items", items ); 4. Forward request to JSP page request.getRequestDispatcher( "WEB-INF/jsp/Admin.jsp" ).forward( request, response ); 5. Extract bean data from beans and display <c:forEach items="${items}" var="item"> …

  13. More About The Example • web.xml • Data Access Object (DAO) Persistent Data Store DAO controller model view user

  14. Recommended by SUN: http://java.sun.com/blueprints/code/projectconventions.html Directory Structure …

  15. … Directory Structure • Recommended by This SUN: \webapp \build \dist \conf \doc \db \lib \compile \runtime \src \web \WEB-INF \jsp \tld build.xml build.properties.sample

  16. Need for Web Application Frameworks • What are missing from Items (MVC version)??

  17. Some Web Application Frameworks • Struts • http://struts.apache.org/ • Spring • http://www.springframework.org/ • More than a MVC framework • Ruby on Rails • http://www.rubyonrails.org/

  18. Web App Development – Where Do We Start? • Control flow driven approach Products Shoping Cart Credit Info checkout buy search Search Results

  19. Web App Development – Where Do We Start? • Data driven approach 3. Application 1. Models 2. Database Schema

More Related