struts.xml配置,三种调用方法的配置

1.使用method属性调用方法

         <!-- 注册请求 -->
         <action name="register" class="com.house.action.UserAction" method="doRegister">
                     <result name="success">/index.jsp</result>
         </action>

2.使用动态方法调用,动态方法可能会带来安全隐患,暴露业务方法给用户,官方不推荐使用

        <!-- 动态方法配置 -->
        <action name="douser" class="com.house.action.UserAction2" >
            <result name="loginsucc">/page/house_list.jsp</result>
            <result name="regsucc">/index.jsp</result>
        </action>      

3.通配符简化<action>配置,实际开发中并不推荐使用通配符,通配符会使得struts.xml的可读性降低,还会增加程序出错的可能性

        <!-- 通配符* -->
        <action name="*User" class="com.house.action.UserAction2" method="{1}" >
            <result name="loginsucc">/page/house_list.jsp</result>
            <result name="regsucc">/index.jsp</result>
        </action>

form表单中上述三种方式相应的配置如下:

       <form action="login.action" method="post">             <!--method属性调用的匹配  -->
       <form action="douser!doLogin" method="post">     <!-- 动态方法匹配 -->
       <form action="doLoginUser" method="post">          <!-- 通配符匹配 -->

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章