Struts2配置文件中使用通配符

来源:互联网 发布:数据分析推荐书籍 编辑:程序博客网 时间:2024/05/21 11:17

形式一:调用相同Action中的不同方法
  1.  <action name="*Action" class="Jcuckoo.LoginRegistAction" method="{1}">
  2.             <result name="input">/login.jsp</result>
  3.             <result name="error">/error.jsp</result>
  4.             <result name="success">/welcome.jsp</result>        
  5.  </action>
其中表达式{1}的值name属性值中第一个*的值。
如果用户请求的URL为loginAction.action,则调用Jcuckoo.LoginRegistAction中的login方法;
如果用户请求的URL为registerAction.action,则调用Jcuckoo.LoginRegistAction中的register方法;

形式二:通过匹配,调用不同的Action的execute方法

  1. <action name="*Action" class="Jcuckoo.{1}Action">
  2.             <result name="input">/login.jsp</result>
  3.             <result name="error">/error.jsp</result>
  4.             <result name="success">/welcome.jsp</result>        
  5. </action>
上面没有出现method属性,故默认调用对应的execute方法
如果用户请求的URL为LoginAction.action,则调用Jcuckoo.LoginAction中的execute方法;
如果用户请求的URL为RegisterAction.action,则调用Jcuckoo.RegisterAction中的execute方法;

形式三:动态结果
  1. <action name="crud_*" class="Jcuckoo.CrudAction" method="{1}">
  2.             <result name="input">/input.jsp</result>
  3.             <result>/{1}.jsp</result>        
  4.  </action>
当处理结果是input时,会转到/input.jsp页面
当处理结果是success时,
    如果crud_create.action,则会执行Jcuckoo.CrudAction中的create方法,并且跳转到/create.jsp;
    如果crud_delete.action,则会执行Jcuckoo.CrudAction中的delete方法,并且跳转到/delete.jsp;



原创粉丝点击