1 / 11

CSCI 6962: Server-side Design and Programming

CSCI 6962: Server-side Design and Programming. Support Classes and the Model-View-Control Architecture. Model-View-Control Architecture. Model = software classes that store/manipulate information gathered by application Usually separate from servlets/JSPs, which interact with them

akasma
Download Presentation

CSCI 6962: Server-side Design and Programming

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. CSCI 6962: Server-side Design and Programming Support Classes and the Model-View-Control Architecture

  2. Model-View-Control Architecture • Model = software classes that store/manipulate information gathered by application • Usually separate from servlets/JSPs, which interact with them • Often interact with databases Classes that model business process Store data Control servlet request View JSP View JSP Access and display data View JSP Database response

  3. Business Model Objects Key idea: • Methods in model objects should implement business model • Methods to validate values • Methods to perform computations • Methods to store information in database Goal: • Separate web programming and business knowledge as much as possible

  4. Model Class Example • Model class for widget application • Contains quantity, name, and email • Method to get total cost of order • Method to get widgets remaining in stock (for validation) • Method to place order in database Constructor Order class request PlaceOrderservlet getAvailable placeOrder QuantityError JSP getAvailable getCost WidgetReceipt JSP Database

  5. Creating Support Classes • File  New File • Choose category Java, type class • Support classes must be in a package • “Library” of related classes • Can define one at this point (added to drop down in future)

  6. Using Model Classes • Other classes that use class must import the package • Servlets use import statement • JSPs use <@ page import tag

  7. Order Support Class • Class includes name of package • Stores data related to model • Constructor stores those values

  8. Order Support Class Would actually query database for these values

  9. Using Model Classes In servlet: • Construct new instance of Order object to store data • Use getQuantityto check whether quantity legal • Use placeOrder to store order information

  10. Using Model Classes Can pass object to JSP as attribute in request (can also store in session for access by all pages)

  11. Using Model Classes • JSP can access object as attribute • Can then access object to extract data

More Related