Struts2自定义方法最佳实践
自定义方法实现
在 struts.xml 配置 method ,并且在对应的 Action 实现对应方法即可。
struts.xml
<action name="login2" class="space.terwer.struts23.LoginAction2" method="myExecute">
<result name="success">/result2.jsp</result>
</action>
Action
public String myExecute() throws Exception {
System.out.println("myExecute called");
return SUCCESS;
}
效果
自定义方法的缺点
参数耦合,逻辑混乱。
自定义方法的优点
一个 Action 可以处理多种不同的逻辑。
最佳实现
Struts2 支持自定义方法,即在 struts.xml 的 Action 元素内定义 method 属性,属性值即为待执行的方法。其中,该方法的声明要与 execute 保持一致。 (不推荐)这种方式容易导致 Action 方法混乱。
原文地址:http://www.cnblogs.com/tangyouwei/p/struts2-custom-method-best-practice-1ap3gz.html
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。