The J2EE BookShop - PowerPoint PPT Presentation

About This Presentation
Title:

The J2EE BookShop

Description:

... customers want to checkout their order, they should supply shipping information ... new order based on the shopping cart and the shipping information ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 22
Provided by: fredri9
Category:

less

Transcript and Presenter's Notes

Title: The J2EE BookShop


1
The J2EE BookShop
  • A detailed walk through of the J2EE BookShop

2
Functional Requirements - repetition
  • The Bookshop is a web shop where the customer can
    do the following
  • Customers should log into the system
  • Customers should be able to browse through all
    available books
  • Customers should be able to view detailed
    information about a particular book

3
Functional Requirments - repetition
  • Customers should be able to add and remove books
    from their shopping cart
  • When customers want to checkout their order, they
    should supply shipping information
  • When checking out, the order should be written in
    the ORDER table and the different books in the
    ORDER_ITEMS table

4
Technical Requirments - repetition
  • Use MVC, Model View Controller
  • The result return from beans or servlet should be
    XML thats transformed to HTML with XSLT (use the
    JSTL tag library). Never print HTML in the beans
    or the Servlets. Output in JSPs are acceptable
  • Try use a Custom tag, for example to return the
    shopping cart

5
Fundamental design ideas
  • The book shop uses these fundamental design ideas
  • Model View Controller (MVC) is used as the base
  • All requests should be handled by a single
    controller servlet
  • Standard J2EE Security is used to secure the site
  • We dont implement the security, we only tell the
    system to use it
  • All dynamic content should be returned to the
    view as XML
  • All XML is transformed into XHTML with XSLT

6
Fundamental design ideas
  • Static layout can be performed in the JSP pages
    for simplicity
  • Only control logic in the controller servlet
  • All business logic in Java Beans
  • All presentation logic in JSPs and XSLT
  • The shopping cart is accessed through a Custom Tag

7
Fundamental design ideas
  • Environment variables (like JDBC Url and the
    different JSP pages) should be configurable at
    deploy time, i.e. should be defined in web.xml

8
web.xml
  • One servlet
  • Named Shop and mapped as /shop
  • se.upright.education.uu.pvk.assignmenttwo.servlets
    .ShopServlet
  • Five init-param entries
  • JDBC_URL
  • CHECKOUT_PAGE
  • SHOW_PAGE
  • THANKYOU_PAGEDETAIL_PAGE

9
web.xml
  • Three Tag Libraries
  • JSTL core
  • c.tld
  • JSTL xml
  • x.tld
  • BookShop
  • bookshop.tld

10
web.xml
  • The URL-pattern / is secured
  • Only users in the role tomcat is allowed
  • Form-login is used
  • login.jsp is the login form
  • login_error.jsp is the error page in case of a
    login failure

11
web.xml
  • ltsecurity-constraintgt
  • ltweb-resource-collectiongt
  • ltweb-resource-namegtTheShoplt/web-resource-nam
    egt
  • lturl-patterngt/lt/url-patterngt
  • lt/web-resource-collectiongt
  • ltauth-constraintgt
  • ltrole-namegttomcatlt/role-namegt
  • lt/auth-constraintgt
  • ltuser-data-constraintgt
  • lttransport-guaranteegtNONElt/transport-guarant
    eegt
  • lt/user-data-constraintgt
  • lt/security-constraintgt
  • ltlogin-configgt
  • ltauth-methodgtFORMlt/auth-methodgt
  • ltform-login-configgt
  • ltform-login-pagegt/login.jsplt/form-login-page
    gt
  • ltform-error-pagegt/login_error.jsplt/form-erro
    r-pagegt
  • lt/form-login-configgt
  • lt/login-configgt

12
Database access
  • All database access is handled by two beans
  • BookListBean
  • OrderBean
  • The book list is only fetched once and then added
    to the application context
  • Bad performance to get the list for each request
  • Unnecessary memory usage if each user have a book
    list of their own
  • Read-only data

13
BookBean
  • A JavaBean that represent one book
  • All properties of the book available with
    getXXX() and setXXX() methods
  • getXml() returns the book in XML format

14
BookListBean
  • The implementation of the book list
  • A Collection with BookBeans is the actual list
  • When created, the BookListBean() connects to the
    database and fetches all books
  • getXml() returns the entire book list as XML
  • getXml() uses BookBean.getXml() to build its XML
    representation

15
ShoppingBean
  • The implementation of the shopping cart
  • Each user should have his own instance of the
    shopping cart
  • addBook(book, quantity) adds a book to the cart
  • If the exists in the cart, only increase the
    quantity
  • removeBook(id, quantity) removes a book
  • If the quantity to remove is more or equal to the
    present, remove the book, otherwise decrease the
    quantity in the cart

16
ShoppingBean
  • getCart() returns the Collection that holds the
    actual cart
  • getXml() returns the shopping cart as XML
  • clear() removes all books from the cart

17
OrderBean
  • Used to create a new order based on the shopping
    cart and the shipping information entered by the
    user
  • The order is written to the ORDER-table
  • The different books are written to the ORDER_ITEM
    table
  • Explicit transaction handling is used
  • Inserting an order is one operation
  • Each book is one operation
  • All operations in one transaction, i.e. write the
    order and all books, or write nothing

18
ShopingCartTag
  • The implementation of the Custom tag to output
    the shopping cart
  • Uses ShoppingBean.getXml() to get the cart

19
XML the book
  • ltbookgt
  • ltidgt1lt/idgt
  • lttitlegtJavaprogramminglt/titlegt
  • ltauthornamegtFredriklt/authornamegt
  • ltauthorsurnamegtAlundlt/authorsurnamegt
  • ltpricegt23lt/pricegt
  • ltpagesgt234lt/pagesgt
  • ltdescriptiongtBla bla blalt/descriptiongt
  • lt/bookgt

20
XML the book list
  • ltbooklistgt
  • ltbookgt
  • ltidgt1lt/idgt
  • lttitlegtJavaprogramminglt/titlegt
  • ltauthornamegtFredriklt/authornamegt
  • ltauthorsurnamegtAlundlt/authorsurnamegt
  • ltpricegt23lt/pricegt
  • ltpagesgt234lt/pagesgt
  • ltdescriptiongtBla bla blalt/descriptiongt
  • lt/bookgt
  • ltbookgt
  • ltidgt2lt/idgt
  • lttitlegtJavaprogramming2lt/titlegt
  • ltauthornamegtKallelt/authornamegt
  • ltauthorsurnamegtSvenssonlt/authorsurnamegt
  • ltpricegt234lt/pricegt
  • ltpagesgt100lt/pagesgt
  • ltdescriptiongtBla bla blalt/descriptiongt
  • lt/bookgt

21
XSL files
  • booklist_xsl.xslt
  • Format the book list
  • BookListBean.getXml()
  • bookdetail_xsl.xslt
  • Format the details about a particular book
  • BookBean.getXml()
  • shoppingcart_xsl.xslt
  • The shopping cart shown in the show page
  • ShoppingBean.getXml()
  • shoppingcart_checkout_xsl.xslt
  • The shopping cart shown in the checkout page
  • ShoppingBean.getXml()
Write a Comment
User Comments (0)
About PowerShow.com