鲜花网站项目(五)————struts2.1的相关配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

    <!-- user的action -->
     <package name="user" namespace="/user" extends="struts-default">
     
              <interceptors>
                <!-- 定义权限控制拦截器 -->
                <interceptor name="myInterceptor"
                    class="com.jikexueyuan.interceptor.LoginInterceptor" >
                    
                    </interceptor>
                <!-- 定义一个包含权限控制的拦截器栈 -->
                <interceptor-stack name="mydefault">

                     <interceptor-ref name="myInterceptor">
                         
                     </interceptor-ref>
                     <interceptor-ref name="defaultStack"/>
                </interceptor-stack>
            </interceptors>
            
        <default-interceptor-ref name="mydefault" />
        <!-- 定义全局处理结果 -->
        <global-results>
            <!-- 逻辑名为login的结果,映射到/login.jsp页面 -->
            <result name="LOGIN">/user/login.jsp</result>
        </global-results>
        
        
        <action name="LoginAction" class="UserAction" method="checkUser">
             <interceptor-ref name="defaultStack" />
            <result name="admin">/index/adminIndex.jsp</result>
            <result name="custom">/index/userIndex.jsp</result>
            <result name="null">/error/error.jsp</result>           
        </action>
        <action name="RegiestAction" class="UserAction" method="regiest">
            <interceptor-ref name="defaultStack" />
            <result name="success">/user/login.jsp</result>
             <result name="error">/error/error.jsp</result>    
        </action>
        <action name="checkAction" class="UserAction" method="checkName">
            <interceptor-ref name="defaultStack" />
        </action>
        <action name="zhuxiaoAction" class="UserAction" method="zhuxiao">
            <interceptor-ref name="defaultStack" />
            <result name="success">/user/login.jsp</result>
        </action>
       </package>
    
    <!-- flower的action -->
    <package name="flower" namespace="/flower" extends="user">
        <action name="getAllFlower" class="flowerAction" method="getAllFlower">
             <interceptor-ref name="defaultStack" />
            <result name="success">/flower/allFlowers.jsp</result>         
        </action>
        <action name="getFlowerByFlowerId" class="flowerAction" method="getFlowerByFlowerId">
            <interceptor-ref name="defaultStack" />
            <result name="success">/flower/flowerInfo.jsp</result>         
        </action>
       </package>
       
       
       <!-- catalog的action -->
       <package name="catalog" namespace="/catalog" extends="user">
        <action name="getAllCatalog" class="catalogAction" method="getAllCatalog">
             <interceptor-ref name="defaultStack" />
            <result name="success">/flower/catalog.jsp</result>         
        </action>
       </package>
              <!-- shopping的action -->
       <package name="shopping" namespace="/shopping" extends="user">
        <action name="addShopping" class="shoppingAction" method="addShopping">   
            <result name="success" type="redirectAction">getAllShopping</result>
        </action>
        <action name="getAllShopping" class="shoppingAction" method="getAllShopping">  
            <result name="success">/shopping/getAllShopping.jsp</result>
        </action>
        <action name="updateShopping" class="shoppingAction" method="updateShopping">  
            <result name="success" type="redirectAction">getAllShopping</result>
        </action>
        <action name="deteleShopping" class="shoppingAction" method="deteleShopping">  
            <result name="success" type="redirectAction">getAllShopping</result>
        </action>
       </package>
           <!-- orderForm的action -->
    <package name="orderForm" namespace="/orderForm" extends="user">
        <action name="addOrderForm" class="orderFormAction" method="addOrderForm">
            <result name="success" type="redirectAction">
              <param name="actionName">getAllOrderForm</param>
              <param name="name">${name}</param>
            </result>        
        </action>
        <action name="getAllOrderForm" class="orderFormAction" method="getAllOrderForm">
            <result name="success">/orderForm/orderForm.jsp</result>         
        </action>
        <action name="deleteOrderFormAction" class="orderFormAction" method="deleteOrderForm">
             <result name="success" type="redirectAction">
              <param name="actionName">getAllOrderForm</param>
              <param name="name">${name}</param>
            </result>         
        </action>
       </package>
       <package name="consumeOrder" namespace="/consumeOrder" extends="user">
        <action name="addConsumeOrder" class="consumeRecorderAction" method="addConsumeOrder">
             <result name="success" type="redirectAction">
              <param name="actionName">getAllConsumeOrder</param>
              <param name="name">${name}</param>
             </result>   
        </action>
        <action name="getAllConsumeOrder" class="consumeRecorderAction" method="getAllConsumeOrder">
            <result name="success">/consumeRocord/consumeRecord.jsp</result>         
        </action>
        
        <action name="getInfoByConsumeOrderId" class="consumeRecorderAction" method="getInfoByConsumeOrderId">
            <result name="success">/consumeInfo/consumeInfo.jsp</result>         
        </action>
       </package>
</struts>    

这里面有两点我需要说

  1. 如果需要用登陆拦截器进行拦截的action不需要特使配置,因为我已经将登陆验证拦截器设置为默认拦截器,而那些不需要登陆拦截器的就需要在action中使用系统的默认拦截器比如登陆验证的action
     <action name="LoginAction" class="UserAction" method="checkUser">
             <interceptor-ref name="defaultStack" />
            <result name="admin">/index/adminIndex.jsp</result>
            <result name="custom">/index/userIndex.jsp</result>
            <result name="null">/error/error.jsp</result>           
        </action>

     2.这个要说的是action之间进行传递数据,只能传递基本类型的数据和字符串,这个是一定的,即便要传送对象,那也要将对象进行序列化成字符串,通过对象输出流存到内存里,在内存中读取字符串acton之间传递数据只有下面这一种方式

        <action name="addConsumeOrder" class="consumeRecorderAction" method="addConsumeOrder">
             <result name="success" type="redirectAction">
              <param name="actionName">getAllConsumeOrder</param>
              <param name="name">${name}</param>
             </result>   
        </action>

第一个name是要传递过去的action(getAllConsumeOrder)的属性名称,第二个name是传值的action(addConsumeOrder)的属性名称。两个aciton都要有set,get方法。

 

posted @ 2017-03-12 20:06  我们不该这样的  阅读(85)  评论(0编辑  收藏  举报