1.普通的方式
复制代码
1
2
3
4
5
6
7
8package com.it.struts2; public class ActionStruts1 { public String execute() { System.out.println("普通的action方式"); return "struts"; } }
复制代码
1
2
3<action name="hello" class="com.it.struts2.ActionStruts1"> <result name="struts" >/hello.jsp</result> </action>
2.接口的方式
复制代码
1
2
3
4
5
6
7
8
9
10package com.it.struts2; import com.opensymphony.xwork2.Action; public class ActionStruts2 implements Action{ @Override public String execute() throws Exception { System.out.println("接口的方式"); return "hello2"; } }
复制代码
1
2
3<action name="hello2" class="com.it.struts2.ActionStruts2"> <result name="hello2">/hello.jsp</result> </action>
3.继承的方式
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14package com.it.struts2; import com.opensymphony.xwork2.ActionSupport; public class ActionStruts3 extends ActionSupport{ @Override public String execute() throws Exception { System.out.println("继承的方式"); return null; } public String save() { System.out.println("save方法"); return null; } }
复制代码
1
2<action name="hello3" class="com.it.struts2.ActionStruts3" method="save"> </action>
action的三种访问方式
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21package com.it.struts2; import com.opensymphony.xwork2.ActionSupport; public class ActionStruts4 extends ActionSupport { public String save() { System.out.println("save"); return null; } public String delete() { System.out.println("delete"); return null; } public String find() { System.out.println("find"); return null; } public String edit() { System.out.println("edit"); return null; } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30<!-- action的3种访问方式 --> <!-- 普通的method方式 --> <!-- <action name="produte_save" class="com.it.struts2.ActionStruts4" method="save"/> <action name="produte_delete" class="com.it.struts2.ActionStruts4" method="delete"/> <action name="produte_find" class="com.it.struts2.ActionStruts4" method="find"/> <action name="produte_edit" class="com.it.struts2.ActionStruts4" method="edit"/> --> <!-- 通配符方式 *: save delete update find {1} :第一个星号的值 --> <!-- <action name="produte_*" class="com.it.struts2.ActionStruts4" method="{1}"/> --> <!-- 动态方法方式(了解) 1 动态方法方式默认是关闭的 需要开启 default.properties 2 页面要使用特殊写法 使用动态方法 <constant name="struts.enable.DynamicMethodInvocation" value="true"/> ***页面地址也需要改变为:produte!save <a href="${pageContext.request.contextPath}/produte!save">商品保存</a> -->
最后
以上就是美满世界最近收集整理的关于Struts2三种action类的写法的全部内容,更多相关Struts2三种action类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复