<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <!-- [开源项目系列]JpetStore5.0 之 struts-config.xml配制文件 定义表单对像JavaFormBeans,本质上属于JavaBeans,在很多应用中只是起到传递用户请求参数 并将其封装转发给Action使用。但是在JpetStore中,将真正的业务逻辑方法也封装在此类中, 另外加上对Action的巧妙设计,整个系统只有一个Action类,用类似IOC依赖注入的方法调用 在JavaFormBeans中的业务方法。 1. AccountBean: 引用了Account类,其封装了用户的详细信息。AccountBean封装了业务方法 如:新建用户,登陆,注销,编辑用户信息等操作。 2. CatalogBean: 引用了Catagory和Product类,其封装了种类信息和产品信息。CatalogBean类 封装了业务方法如:查看某一类型的产品,查看具体某一产品信息,查找产品等。 3. CartBean:引用了Cart类,封装了购物车的信息。CartBean类封装了购物操作。 如:将产品增加购物车,将产品移除购物车,查看购物车,结账等购物操作。 4. OrderBean:引用了Order类,封装了订货单的信息。OrderBean类封装了结账生成账单之后 付款的操作。如:编辑订购单,成订购单,提交订购单。 --> <form-beans> <form-bean name="accountBean" type="com.ibatis.jpetstore.presentation.AccountBean"/> <form-bean name="catalogBean" type="com.ibatis.jpetstore.presentation.CatalogBean"/> <form-bean name="cartBean" type="com.ibatis.jpetstore.presentation.CartBean"/> <form-bean name="orderBean" type="com.ibatis.jpetstore.presentation.OrderBean"/> </form-beans> <!-- 定义全局异常处理 --> <global-exceptions> <exception key="errors.general" type="java.lang.Exception" path="/common/Error.jsp"/> </global-exceptions> <!-- 定义全局转发 --> <global-forwards> <forward name="failure" path="/common/Error.jsp"/> <forward name="error" path="/common/Error.jsp"/> <forward name="signon" path="/account/SignonForm.jsp"/> <forward name="newOrderForm" path="/shop/newOrderForm.shtml"/> </global-forwards> <!-- 在框架内进行流程控制,作用是将请求的URI映射到具体的Action,并且将Action与 ActionFormBean相关联。 path:配制访问URI地址。 type:配制处理请求的Action类的全路径。 name:使用ActionFormBean。 forward:定义转发,公可被当前的Action所使用。 message-resources:消息资源文件,对应的资源文件的根目录为src。 plug-in:通常用于将插件增加到Struts控制器中。Struts插件使用多用于分配资源或者 数据库备份连接资源或者是JNDI资源。如果要对插件部分进行全面了了解需要有一个专题来 阐述。 另外: scope:可定义ActionFormBean的有效范围。 --> <action-mappings> <!-- 主应用。当访问/shop/index.shtml的地址,服务器返回/catalog/Main.jsp内容。 --> <action path="/shop/index" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" parameter="*" validate="false"> <forward name="success" path="/catalog/Main.jsp"/> </action> <!-- CATALOG ACTIONS --> <!-- 搜索功能。当访问/shop/searchProducts地址,服务器返回/SearchProducts.jsp --> <action path="/shop/searchProducts" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" scope="session" validate="false"> <forward name="success" path="/catalog/SearchProducts.jsp"/> </action> <!-- 搜索列表视图功能。 --> <action path="/shop/switchSearchListPage" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" scope="session" parameter="switchProductListPage" validate="false"> <forward name="success" path="/catalog/SearchProducts.jsp"/> </action> <!-- 查看种类功能。当访问/shop/viewCategory地址, 服务器返回/catalog/Category.jsp --> <action path="/shop/viewCategory" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" scope="session" validate="false"> <forward name="success" path="/catalog/Category.jsp"/> </action> <!-- 产品列表视图功能。 --> <action path="/shop/switchProductListPage" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" scope="session" validate="false"> <forward name="success" path="/catalog/Category.jsp"/> </action> <!-- 查看产品列表功能。当访问/shop/viewProduct.shtml地址, 服务器返回/catalog/Product.jsp --> <action path="/shop/viewProduct" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" scope="session" validate="false"> <forward name="success" path="/catalog/Product.jsp"/> </action> <!-- 产品项列表视图功能。 --> <action path="/shop/switchItemListPage" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" scope="session" validate="false"> <forward name="success" path="/catalog/Product.jsp"/> </action> <!-- 查看产品项功能。当访问/shop/viewProduct.shtml地址, 服务器返回/catalog/Product.jsp --> <action path="/shop/viewItem" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" scope="session" validate="false" input="/catalog/Product.jsp"> <forward name="success" path="/catalog/Item.jsp"/> </action> <!-- CART ACTIONS --> <!-- 增加产品到购物车功能。 当访问/shop/addItemToCart.shtml地址,服务器返回/cart/Cart.jsp --> <action path="/shop/addItemToCart" type="org.apache.struts.beanaction.BeanAction" name="cartBean" scope="session" validate="false"> <forward name="success" path="/cart/Cart.jsp"/> </action> <!-- 移除产品从购物车功能。 当访问/shop/removeItemToCart.shtml地址,服务器返回/cart/Cart.jsp --> <action path="/shop/removeItemFromCart" type="org.apache.struts.beanaction.BeanAction" name="cartBean" scope="session" validate="false"> <forward name="success" path="/cart/Cart.jsp"/> </action> <!-- 更新购物车功能。 当访问/shop/updateCartQuantities地址,服务器返回/cart/Cart.jsp --> <action path="/shop/updateCartQuantities" type="org.apache.struts.beanaction.BeanAction" name="cartBean" scope="session" validate="false"> <forward name="success" path="/cart/Cart.jsp"/> </action> <!-- 付账功能。 当访问/shop/check.shtml地址,服务器返回/cart/Checkout.jsp --> <action path="/shop/checkout" type="org.apache.struts.beanaction.BeanAction" name="orderBean" scope="session" parameter="newOrderForm" validate="false" > <forward name="success" path="/cart/Checkout.jsp"/> </action> <!-- 查看购物车功能。 当访问/shop/viewCart.shtml地址,服务器返回/cart/Cart.jsp --> <action path="/shop/viewCart" type="org.apache.struts.beanaction.BeanAction" name="cartBean" scope="session" validate="false"> <forward name="success" path="/cart/Cart.jsp"/> </action> <!-- 改变购物车视图功能。 当访问/shop/switchCartPage地址,服务器返回/cart/Cart.jsp --> <action path="/shop/switchCartPage" type="org.apache.struts.beanaction.BeanAction" name="cartBean" scope="session" validate="false"> <forward name="success" path="/cart/Cart.jsp"/> </action> <!-- 改变购我的列表视图功能。 当访问/shop/switchMyListPage.shtml地址,服务器返回/cart/Cart.jsp --> <action path="/shop/switchMyListPage" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" validate="false"> <forward name="success" path="/cart/Cart.jsp"/> </action> <!-- ACCOUNT ACTIONS --> <!-- 新建用户表单功能。 当访问/shop/newAccountForm.shtml地址,服务器返回/accountnt/NewAccountForm.jsp --> <action path="/shop/newAccountForm" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" parameter="*" validate="false"> <forward name="success" path="/account/NewAccountForm.jsp"/> </action> <!-- 新建用户功能。 当访问/shop/newAccount.shtml地址,服务器返回/accountnt/NewAccount.jsp --> <action path="/shop/newAccount" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" validate="true" input="/account/NewAccountForm.jsp"> <forward name="success" path="/shop/index.shtml"/> </action> <!-- 编辑用户表单功能。 当访问/shop/editAccountForm.shtml地址,服务器返回/accountnt/EditAccountForm.jsp --> <action path="/shop/editAccountForm" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" validate="false"> <forward name="success" path="/account/EditAccountForm.jsp"/> </action> <!-- 编辑用户功能。 当访问/shop/editAccount.shtml地址,服务器返回/accountnt/EditAccount.jsp --> <action path="/shop/editAccount" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" validate="true" input="/account/EditAccountForm.jsp"> <forward name="success" path="/shop/index.shtml"/> </action> <!-- 用户登陆输入表单功能。 当访问/shop/signonForm.shtml地址,服务器返回/accountnt/SignonForm.jsp --> <action path="/shop/signonForm" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" parameter="*" validate="false"> <forward name="success" path="/account/SignonForm.jsp"/> </action> <!-- 用户登陆功能。 当访问/shop/signon.shtml地址,服务器返回/accountnt/Signon.jsp --> <action path="/shop/signon" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" validate="false"> <forward name="success" path="/shop/index.shtml"/> </action> <!-- 用户注销功能。 当访问/shop/signoff.shtml地址,服务器返回/shop/index.jsp --> <action path="/shop/signoff" type="org.apache.struts.beanaction.BeanAction" name="accountBean" scope="session" validate="false"> <forward name="success" path="/shop/index.shtml"/> </action> <!-- ORDER ACTIONS --> <!-- 添加订货表单功能。 当访问/shop/newOrderForm地址,服务器返回/order/NewOrderForm.jsp --> <action path="/shop/newOrderForm" type="org.apache.struts.beanaction.BeanAction" name="orderBean" scope="session" validate="false"> <forward name="success" path="/order/NewOrderForm.jsp"/> </action> <!-- 添加订货功能。 当访问/shop/newOrder地址,服务器返回/order/ConfirmOrder.jsp --> <action path="/shop/newOrder" type="org.apache.struts.beanaction.BeanAction" name="orderBean" scope="session" validate="true" input="/order/NewOrderForm.jsp"> <forward name="confirm" path="/order/ConfirmOrder.jsp"/> <forward name="shipping" path="/order/ShippingForm.jsp"/> <forward name="success" path="/order/ViewOrder.jsp"/> </action> <!-- 查看订货单列表功能。 当访问/shop/listOrders.shtml地址,服务器返回/order/ListOrders.jsp --> <action path="/shop/listOrders" type="org.apache.struts.beanaction.BeanAction" name="orderBean" scope="session" validate="false"> <forward name="success" path="/order/ListOrders.jsp"/> </action> <!-- 改变订货单页面功能。 当访问/shop/switchOrderPage地址,服务器返回/order/ListOrders.jsp --> <action path="/shop/switchOrderPage" type="org.apache.struts.beanaction.BeanAction" name="orderBean" scope="session" validate="false"> <forward name="success" path="/order/ListOrders.jsp"/> </action> <!-- 查看订货单功能。 当访问/shop/viewOrder.shtml地址,服务器返回/order/ViewOrder.jsp --> <action path="/shop/viewOrder" type="org.apache.struts.beanaction.BeanAction" name="orderBean" scope="session" validate="false"> <forward name="success" path="/order/ViewOrder.jsp"/> </action> </action-mappings> <!-- 资源文件 --> <message-resources parameter="properties.messages"/> <!-- 验证插件 --> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> </struts-config>