struts2如何访问action的特定方法

来源:互联网 发布:网络信息平台建设方案 编辑:程序博客网 时间:2024/05/20 16:45

在使用struts2的时候,我们一般会在一个action中处理很多事情,那么不指定方法就会访问action的默认方法execute,如果指定了则会访问指定的方法。

例如:

http://localhost/struts2/simple/hello.action

默认调用hello这个action中的execute方法!


访问指定方法

方式一:

http://localhost/struts2/simple/hello!say.action

可以调用hello这个action中的say方法

方式二:

http://localhost/struts2/simple/hello.action?method:say=xxx

可以调用say方法,在这里,参数的名称是:method:say,这是最主要的,struts2正是

根据参数的名称来决定该调用哪个方法,而不是参数的值,所以参数的值可以是任意的

方式三:

struts2的配置文件的action标签中存在一个method属性,用来指定访问特定的方法

<action name="hello" class="helloAction" method="say">

方式四:

<action name="hello_*" class="helloAction" method="{1}">

这样在页面中的action路径可写为hello_say.action就是访问say方法了。


原创粉丝点击