1 / 21

The J2EE BookShop

The J2EE BookShop. A detailed walk through of the J2EE BookShop. 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

love
Download Presentation

The J2EE BookShop

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. 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 that’s 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 don’t 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 • <security-constraint> • <web-resource-collection> • <web-resource-name>TheShop</web-resource-name> • <url-pattern>/*</url-pattern> • </web-resource-collection> • <auth-constraint> • <role-name>tomcat</role-name> • </auth-constraint> • <user-data-constraint> • <transport-guarantee>NONE</transport-guarantee> • </user-data-constraint> • </security-constraint> • <login-config> • <auth-method>FORM</auth-method> • <form-login-config> • <form-login-page>/login.jsp</form-login-page> • <form-error-page>/login_error.jsp</form-error-page> • </form-login-config> • </login-config>

  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 it’s 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 • <book> • <id>1</id> • <title>Javaprogramming</title> • <authorname>Fredrik</authorname> • <authorsurname>Alund</authorsurname> • <price>23</price> • <pages>234</pages> • <description>Bla bla bla</description> • </book>

  20. XML – the book list • <booklist> • <book> • <id>1</id> • <title>Javaprogramming</title> • <authorname>Fredrik</authorname> • <authorsurname>Alund</authorsurname> • <price>23</price> • <pages>234</pages> • <description>Bla bla bla</description> • </book> • <book> • <id>2</id> • <title>Javaprogramming2</title> • <authorname>Kalle</authorname> • <authorsurname>Svensson</authorsurname> • <price>234</price> • <pages>100</pages> • <description>Bla bla bla</description> • </book> • </booklist>

  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()

More Related