(21) java web的struts2框架的使用-Action实现的三种方式
生活随笔
收集整理的這篇文章主要介紹了
(21) java web的struts2框架的使用-Action实现的三种方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?上一篇介紹了struts使用的四個步驟。
其中在開發action的時候,可以有三種實現方式:
1,寫一個類,繼承與ActionSupport
2,寫一個類,實現Action接口
3,寫一個類,實現業務方法,既不繼承ActionSupport,也不實現Action接口
?
一,繼承ActionSupport
package gy.actions;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport {private static final long serialVersionUID = 1L;public String login() {System.out.println("login funciton called");return SUCCESS;}}對應的配置
<action name="user_*" class="gy.actions.UserAction" method="{1}"><result name="success">/success.html</result><result name="error">/fail.html</result></action>?
二,實現Action接口
package gy.actions;import com.opensymphony.xwork2.Action;public class UserActionSecond implements Action {@Overridepublic String execute() throws Exception {System.out.println("second action implement function called.");return SUCCESS;} }對應的配置
<action name="user_second" class="gy.actions.UserActionSecond"><result name="success">/success.html</result><result name="error">/fail.html</result></action>可以看到,不用配置method屬性。因為是實現了Action接口,方法名固定
?
三,不繼承也不實現
package gy.actions;public class UserActionThird {public String login() {System.out.println("third function called");return "success";} }對應的配置
<action name="user_third" class="gy.actions.UserActionThird" method="login"><result name="success">/success.html</result><result name="error">/fail.html</result></action>
?
轉載于:https://www.cnblogs.com/yangzigege/p/9460208.html
總結
以上是生活随笔為你收集整理的(21) java web的struts2框架的使用-Action实现的三种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Luogu P2982 [USACO10
- 下一篇: 回过头来看对象的四种状态强软弱虚引用的理