Purpose

The purpose of this workshop is to migrate the shopping cart which we created in Session Based Shopping Cart Article and use Struts 1 framework for MVC. The article is not intended to explain all struts features like localization, validation framework, error handling etc.

Prerequisites

  • Knowledge about struts1 application framework
  • This articles assume that a session based shopping cart is already developed as explained in Session Based Shopping Cart Article . All requirements are same as the previous article.

Analysis and design

Our analysis and design will not be as exhaustive as the previous session based shopping cart. We already have the components designed and responsibility assigned (Also have code available). We will use the previous components and review the changes required.

Based on the previous article below are the list of components:
1. ModelList.jsp
2. ShoppingCart.jsp
3. CartBean.java
4. CartItemBean.java
5. CartController.java


We will move most of the logic from CartController which was a servlet and implement a Struts Action class instead. Hence, we create a new class CartAction which extends Action class.

If you look at the ModelList or ShoppingCart form(HTML Form), each form submits details of an Item or Model. ModelList has Add action on Item and ShoppingCart.jsp has Update and Delete action on Item. Based on this information, we can modify the CartItemBean into CartItemForm which extends Struts ActionForm class. Instance of the ActionForm will be provided as input to CartAction.

Hence, the revised list of components would look something like:
1. ModelList.jsp
2. ShoppingCart.jsp
3. CartBean.java
4. CartItemForm.java
5. CartAction.java

 

Development environment structure:

I prefer starting a struts 1 application by publishing the struts-blank application to Tomcat. The struts-blank application can be download from Apache website. The published struts-blank application provides a sample of struts-config.xml and all the required libraries to run a struts application.

However, at the end of the application we have provided a link to down the Web Archive (WAR) file of the whole StrutsShoppingCart application (with Source code).

StrutsShoppingCart
  - ModelList.jsp
  - ShoppingCart.jsp
     WEB-INF
      - struts-config.xml
      - web.xml
      src
        - in.techfreaks.struts.cart.bean.CartBean.java
        - in.techfreaks.struts.cart.form.CartItemForm.java
        - in.techfreaks.struts.cart.action.CartAction.java
      classes
      lib
      - jstl.jar
      -standard.jar
      - <ALL Struts required Lib >

We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.