Struts2配置文件详解三

 

1.2.3  示例2

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

    "http://struts.apache.org/dtds/struts-2.0.dtd">

 

<struts>

    <package name="bookManage" namespace="/manage/book" extends="books-manage">

<!—上传,可以设置上传类型及上传的文件大小à

       <action name="uploadZip" class="***.action.FileAction" method="uploadZip" >

           <interceptor-ref name ="fileUpload">

                <param name ="allowedTypes">

                    application/zip,application/x-zip-compressed

                </param >

                <param name ="maximumSize">20480000</param > 

            </interceptor-ref >

            <interceptor-ref name="defaultStack"></interceptor-ref>

           <result name="toUploadZip">/html/manage/book/uploadZip.jsp</result>  

           <result name="uploadZip">/html/manage/book/saveing.jsp</result>      

           <result name="input">/html/manage/book/uploadZip.jsp</result>

       </action>

      

       <action name="uploadBookCover" class="***.action.FileAction" method="uploadBookCover" >

           <interceptor-ref name ="fileUpload">

                <param name ="allowedTypes">

               image/bmp,image/png,image/x-png,image/gif,image/jpeg,image/pjpeg,image/jpg

                </param >

                <param name ="maximumSize">1024000</param > 

            </interceptor-ref >

            <interceptor-ref name="defaultStack"></interceptor-ref>

           <result name="uploadBookCover" >

/html/manage/book/uploadBookCoverSuccess.jsp

</result>   

           <result name="input">/html/manage/book/uploadBookCover.jsp</result>

       </action>

      

       <action name="file" class="***.action.FileAction">

           <result name="toUploadBookCover" >

/html/manage/book/uploadBookCover.jsp

</result>

           <result name="toUploadZip" >/html/manage/book/uploadZip.jsp</result>

           <result name="unZip">/html/manage/book/bookBatchSave.jsp</result> 

           <result name="saveing">/html/manage/book/saveing.jsp</result> 

           <result name="input" >/html/manage/book/unZip.jsp</result> 

       </action>

       <!—redirectActionà

       <action name="book" class="***.action.BookManageAction">

           <interceptor-ref name="bookManageTopNavigatorStack"></interceptor-ref>

           <result name="manage" >/html/manage/book/bookManage.jsp</result>

           <result name="initTree" >/html/manage/book/bookManageTree.jsp</result>

           <result name="batchSave" >/html/manage/book/unsavedBookList.jsp</result>

           <result name="listCategory" >/html/manage/book/categoryList.jsp</result>

           <result name="listBook" >/html/manage/book/bookList.jsp</result>

           <result name="toListBook" type="redirectAction">

              <param name="namespace">/manage/book</param>

              <param name="actionName">book</param>

              <param name="method">listBook</param>

              <param name="industryId">${industryId}</param>

              <param name="groupId">${categoryId}</param>

              <param name="page">${page}</param>

              <param name="empty"></param>

             <param name="supressEmptyParameters">true</param>

           </result>                  

           <result name="toEditBook" >/html/manage/book/bookEdit.jsp</result>

           <result name="toAddBook" >/html/manage/book/bookAdd.jsp</result>

       </action>

       <!—redirectà

       <action name="chapter" class="***.action.ChapterManageAction">

           <interceptor-ref name="bookManageTopNavigatorStack"></interceptor-ref>

           <result name="listChapter" >/html/manage/book/chapterList.jsp</result>   

           <result name="toListChapter"  type="redirect">

chapter!listChapter.action?industryId=${industryId}&amp;groupId=${categoryId}&amp;bookId=${bookId}&amp;page=${page}

</result>       

           <result name="view" >/html/manage/book/chapterView.jsp</result>

       </action>

<!--使用通配符映射(wildcard mappings)方式:在struts.xml文件中配置<action…>元素时,它的nameclassmethod属性都可支持通配符,这种通配符的方式是另一种形式的动态方法调用。当我们使用通配符定义Actionname属性时,相当于用一个元素action定义了多个逻辑Action  à

<action name="user_*"

class="***.action.UserAction" method="{1}">

<result name="success">/success.jsp</result>

<result name="error">/error.jsp</result>

</action>

<!-将匹配 "/foo/edit" 或者 "/foo/save".-à

<action name="*/*" method="{2}" class="actions.{1}">

 

<!--chain的使用主要是为了共享表单传递的数据,即实现一个表单参数传递多个action的目的。action在链式调用过程中,所有action都会接收表单参数来对action的数据进行赋值,不过在赋值之前会先使用前面的action的数 据来进行赋值,即,如果前面action中的数据及表单参数名字一样的时候,表单参数的值会覆盖前面action传递过来的参数值。另外,如果在定向到input视图前有错误(如actionhasError方法返回true)和异常发生,且返回的input视图的type"chain"(即返回到另一个action)时,这个action的方法必须为input,否则这个方法不会执行,而是会直接定位到物理视图。 skipActions中所有的action都无条件的执行à

<action name="createAccount" class="***action">

        <result type="chain">login</result>

    </action>

    <action name="login" class="...">

        <!-- Chain to another namespace -->

        <result type="chain">

            <param name="actionName">dashboard</param>

            <param name="namespace">/secure</param>

<param name="method">listBook</param>

<param name=”skipActions”>actionname以逗号隔开</>

        </result>

    </action>

 

    </package>

</struts>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值