1 / 18

CS320 Web and Internet Programming Web Applications and MVC

Learn about web application development using MVC architecture. Explore web.xml, ANT, and MVC frameworks like Struts and Spring.

rollerj
Download Presentation

CS320 Web and Internet Programming Web Applications and MVC

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. CS320 Web and Internet ProgrammingWeb Applications and MVC Chengyu Sun California State University, Los Angeles

  2. Overview • Web application • web.xml • More ANT tricks • MVC

  3. Java Web Application • Components • Servlets • JSPs • Classes • Static documents (HTML, images, sounds etc.) • Meta information • Everything in the same context is considered part of one application

  4. Directory Structure • webapp root • WEB-INF/ • WEB-INF/classes • WEB-INF/lib • WEB-INF/web.xml (deployment descriptor)

  5. web.xml <?xml version="1.0"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4" > <description> A Java web application example for CS320. </description> <display-name>CS320 Web App Example</display-name> </web-app>

  6. Some <web-app> Elements • <welcome-file-list> • <servlet> and <servlet-mapping> • <session-config> • <context-param>

  7. More About web.xml • Java Servlet 2.4 Specification • SRV.13.4

  8. Problems of Deployment • Reloadable context • Degrade server performance • Somewhat inconsistent behavior • Classes and JSP are automatically recognized • Changes to .tld are automatically recognized • Changes to web.xml are not automatically recognized • Problems with included pages • Non-reloadable context • Manual deployment using the manager interface is tedious

  9. ANT to the Rescue • Both developed originally by James Duncan Davidson • A number of ANT tasks designed specifically for web development with Tomcat • Usage • Include catalina-ant.jar in $CATALINE_HOME/server/lib • <taskdef> in build.xml

  10. Create a WAR File • WAR – JAR file for web applications • <war> • destfile • webxml • <classes> • <lib> • <webinf> • <metainf>

  11. Tomcat Manager Tasks • <deploy> • <undeploy> • <start> • <stop> • <reload> • and a few others • work both locally and remotely

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

  13. 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

  14. MVC Control Flow ... model 2 3 controller 1 4 browser view 5 Client Server

  15. ... 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

  16. MVC Example • Model • User.java, Item.java • View • Login.jsp, Admin.jsp, User.jsp • Controller • LoginController.java, LogoutController.java • AdminController.java, UserController.java

  17. MVC Example – User.html Item UserController browser User.jsp Client Server

  18. MVC Frameworks • Struts • http://struts.apache.org • Backed by SUN and Apache Foundation • Mature framework • Widely used and well supported • Spring • http://www.springframework.org • New buzz in J2EE community • More flexible • Less dependency on the framework

More Related