博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Struts2方法调用的三种方式
阅读量:4628 次
发布时间:2019-06-09

本文共 941 字,大约阅读时间需要 3 分钟。

在Struts2中方法调用概括起来主要有三种形式

 

第一种方式:指定method属性

/success.jsp

 

这样Struts2就会调用Student 中的add方法。

 

第二种方式:动态方法调用(DMI)

用这种方法需要设置一个常量

动态方法调用是指表单元素的action并不是直接等于某个Action的名字,而是以如下形式来指定Form的action属性

action = "action!methodName.action"

在struts.xml中定义如下Action

/add.jsp
/delete.jsp

StudentAction代码为

public class StudentAction extends ActionSupport {    public String add(){        return "add";    }    public String delete(){        return "delete";    }}

 

则在JSP中用如下方式调用方法

  新增学生    删除学生

第三种方式:通配符(推荐使用)

/student{1}.jsp

 

  新增学生    删除学生

 

studentadd就会调用StudentAction中的add方法 然后跳转到studentadd.jsp

studentdelete就会调用StudentAction中的delete方法 然后跳转到studentdelete.jsp

 

Struts2支持动态方法调用,它指的是一个Action中有多个方法,系统根据表单元素给定的action来访问不同的方法,而不用写多个Action。

 

 

 

转载于:https://www.cnblogs.com/snake-hand/p/3177761.html

你可能感兴趣的文章
Excel的数据分析—排位与百分比
查看>>
讯飞语音识别Android-Demo
查看>>
引入css的四种方式
查看>>
Mysql蠕虫复制
查看>>
centos7+ansible自动化工具使用
查看>>
iOS开发UI篇—transframe属性(形变)
查看>>
3月7日 ArrayList集合
查看>>
正则替换
查看>>
jsp 环境配置记录
查看>>
本地视频播放黑屏,有声音
查看>>
Python3-Cookbook总结 - 第一章:数据结构和算法
查看>>
Python03
查看>>
LOJ 2537 「PKUWC2018」Minimax
查看>>
使用java中replaceAll方法替换字符串中的反斜杠
查看>>
Android初学第36天
查看>>
Some configure
查看>>
.net core 中的[FromBody]
查看>>
json_encode时中文编码转正常状态
查看>>
流量调整和限流技术 【转载】
查看>>
Axure 全局辅助线(转)
查看>>