Struts2学习四

您所在的位置:网站首页 struts2动态方法调用 Struts2学习四

Struts2学习四

2024-07-14 08:19| 来源: 网络整理| 查看: 265

© 版权声明:本文为博主原创文章,转载请注明出处

Struts2动态方法调用

  - 默认:默认执行方法中的execute方法,若指定类中没有该方法,默认返回success

/add.jsp /error.jsp

  - 指定method属性:执行method属性中定义的方法,没有该方法,页面报错

/add.jsp /error.jsp

  - 通配符方式:使用*作用通配符,若没有配置method,默认执行execute,没有execute方法,默认返回success;

          若配置method,执行method属性中定义的方法,没有该方法,则报错

/{1}.jsp /error.jsp

  - 感叹号方法:在!(感叹号)后面指定方法名,需在package中设置strict-method-invocation="false",并且开启动态方法调用(老版本只需开启动态方法调用即可)

/add.jsp /error.jsp

实例

1.项目结构

2.pom.xml

4.0.0 org.struts Struts2-DynamicMethod war 0.0.1-SNAPSHOT Struts2-DynamicMethod Maven Webapp http://maven.apache.org 2.5.10 UTF-8 junit junit 4.12 test org.apache.struts struts2-core ${struts.version} Struts2-DynamicMethod

3.web.xml

struts org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter struts /*

4.DynamicMethod.java

package org.struts.dynamicmethod.action; import com.opensymphony.xwork2.ActionSupport; public class DynamicMethod extends ActionSupport { private static final long serialVersionUID = 1L; public String add() { return "add"; } public String modify() { return "modify"; } public String delete() { return "delete"; } }

5.struts.xml

/search.jsp /error.jsp /add.jsp /error.jsp /modify.jsp /error.jsp /{1}.jsp /error.jsp

6.index.jsp

动态方法调用测试 查询 新增 修改 删除

7.delete.jsp

Insert title here This is delete.jsp

8.add.jsp

Insert title here This is add.jsp

9.modify.jsp

Insert title here This is modify.jsp

10.search.jsp

Insert title here This is search.jsp

11.效果预览

  11.1 主界面

  

  11.2 查询(默认方式,类中无execute方法,默认返回name="success"的result对应的界面)

  

  11.3 新增(指定method属性,执行add方法)

  

  11.4 修改(感叹号方式,执行modify方法)

  

  11.5 删除(通配符方式,执行delete方法)

  

参考:http://www.imooc.com/video/8999



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3