zoukankan      html  css  js  c++  java
  • Struts2-学习笔记系列(6)-动态调用action

    动态调用之前需要配置:

    <!--动态方法调用-->
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

    配置struts

     1 <package name="zcx.controller" namespace="/" extends="struts-default">
     2 
     3     <action name="login" class="zcx.controller.LoginAction">
     4 
     5         <result name="success">/WEB-INF/content/welcome.jsp</result>
     6 
     7     </action>
     8 
     9     <action name="regist" class="zcx.controller.LoginAction" method="regist">
    10 
    11         <result name="success">/WEB-INF/content/welcome.jsp</result>
    12 
    13     </action>
    14 
    15     <!--处理所有的action-->
    16 
    17     <action name="*">
    18 
    19         <!--返回对应的页面-->
    20 
    21         <result>/WEB-INF/content/{1}.jsp</result>
    22 
    23     </action>
    24 
    25 </package>

    实现regist方法

     1 public String regist() throws Exception
     2 
     3 {
     4 
     5     ActionContext.getContext().getSession()
     6 
     7             .put("user" , getUser());
     8 
     9     addActionMessage("恭喜您," + getUser() + ",您已经注册成功!");
    10 
    11     return SUCCESS;
    12 
    13 }

    6.3通配符

     1 <package name="zcx" extends="struts-default">
     2 
     3     <!-- 使用模式字符串定义Action的name,指定所有以Action结尾的请求,
     4 
     5     都可用LoginRegistAction来处理,method属性使用{1},
     6 
     7     这个{1}代表进行模式匹配时第一个*所代替的字符串 -->
     8 
     9     <action name="*Action" class="zcx.controller.LoginAction"
    10 
    11             method="{1}">
    12 
    13         <!-- 定义逻辑视图和物理视图之间的映射关系 -->
    14 
    15         <result name="error">/WEB-INF/content/error.jsp</result>
    16 
    17         <result>/WEB-INF/content/welcome.jsp</result>
    18 
    19     </action>
    20 
    21     <action name="*">
    22 
    23         <result>/WEB-INF/content/{1}.jsp</result>
    24 
    25     </action>
    26 
    27 </package>

    action result type

    解压:struts2-core-2.3.16.3.jar文件,找到里面的struts.default文件可查看详细结果类型配置

    Redirect:重定向到其他页面;同时可以使用表达式:test.action?getdata=${input.name}

    RedirectAction:重定向到其他action

    全局result

    对所有action都有效。比如,若是系统出错需要跳转到一个页面,可以使用全局result

  • 相关阅读:
    ASP.NET学习篇(4)——服务器端的控件【转自www.bitsCN.com】
    sql2005 管道的另一端上无任何进程解决方法
    SQL服务器名称的更改
    如何辨别移动硬盘的好坏
    ADO绑定SQL数据库过程
    SQL变量的使用
    SQL子查询
    什么SQL解发器?
    什么是存储过程呢?
    显式事务和隐式事务之间有什么区别?
  • 原文地址:https://www.cnblogs.com/zijiyanxi/p/5559685.html
Copyright © 2011-2022 走看看