AppFuse1.8中BaseAction的一些主要方法说明
2005-12-05 15:11
477 查看
功能:
通过请求的参数来决定该执行哪一个方法,而不像一般的Action,从Execute方法执行。在一个窗体中包括两个以上同名的按钮时,由Struts来决定具体执行那个按钮操作,减少了Action类,增加了请求处理的灵活性AppFuse1.7与AppFuse1.8的BaseAction区别
AppFuse1.7是继承LookupDispatchAction, 需要复写 getKeyMethodMap()方法具体可参考http://blog.csdn.net/GOALSTAR/archive/2005/12/05/543802.aspx
AppFuse1.8是继承DispatchAction
AppFuse1.8中BaseAction的主要方法
1.getBean()方法,得到Bean的对象
2.convert() 对象转换方法,用来实现POJOs à ActionForm & ActionForm à POJOs 的转换
3.execute()的方法
在AppFuse1.8中BaseAction是继承DispatchAction , 使用struts时我们经常会用到DispatchAction.有了这个类,我们不需要针对每一个Action都要写一个特定的类,而是可以把一些相关的方法放到一个类中.
DispatchActon中使用了reflection来根据你传入的method参数的值来获取相应的参数来处理你的请求.正如他的方法 -- 他根据你传入的请求参数,用不同的方法来处理你的请求.
只要看看struts中DispatchAction(以下简写做DA)的源文件你就会发现,它有一个dispatchMethod方法,接受5个参数.其中4个就是我们通常的struts action里的(mapping,request,response,form),还有一个参数就是指定方法的参数的名字.
Ø Struts-config.xml中的配置
<action path="/editUser" ype="smarthings.webapp.action.UserAction" name="userForm" scope="request"
input="list" roles="admin" parameter="method" unknown="false" validate="false" >
<forward name="viewUsers" path="/editUser.html?method=Search( edit / save / delete )"/>
</action>
然后在Action中具体的实现Action都是继承了BaseAction的.比如
通过请求的参数来决定该执行哪一个方法,而不像一般的Action,从Execute方法执行。在一个窗体中包括两个以上同名的按钮时,由Struts来决定具体执行那个按钮操作,减少了Action类,增加了请求处理的灵活性AppFuse1.7与AppFuse1.8的BaseAction区别
AppFuse1.7是继承LookupDispatchAction, 需要复写 getKeyMethodMap()方法具体可参考http://blog.csdn.net/GOALSTAR/archive/2005/12/05/543802.aspx
AppFuse1.8是继承DispatchAction
AppFuse1.8中BaseAction的主要方法
1.getBean()方法,得到Bean的对象
public Object getBean (String name) { if (ctx == null) { ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext()); } return ctx.getBean(name); } |
// 调用ConvertUtil#convert(java.lang.Object) protected Object convert (Object o) throws Exception { return ConvertUtil.convert(o);} |
public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (isCancelled(request)) { try { getMethod("cancel"); return dispatchMethod(mapping, form, request, response, "cancel"); } catch (NoSuchMethodException n) { log.warn("No 'cancel' method found, returning null"); return cancelled(mapping, form, request, response); } } // Check to see if methodName indicated by request parameter String actionMethod = getActionMethodWithMapping(request, mapping); if (actionMethod != null) { return dispatchMethod(mapping, form, request, response, actionMethod); } else { String[] rules = {"edit", "save", "search", "view"}; for (int i = 0; i < rules.length; i++) { // apply the rules for automatically appending the method name if (request.getServletPath().indexOf(rules[i]) > -1) { return dispatchMethod(mapping, form, request, response, rules[i]); } } } return super.execute(mapping, form, request, response); } |
DispatchActon中使用了reflection来根据你传入的method参数的值来获取相应的参数来处理你的请求.正如他的方法 -- 他根据你传入的请求参数,用不同的方法来处理你的请求.
只要看看struts中DispatchAction(以下简写做DA)的源文件你就会发现,它有一个dispatchMethod方法,接受5个参数.其中4个就是我们通常的struts action里的(mapping,request,response,form),还有一个参数就是指定方法的参数的名字.
Ø Struts-config.xml中的配置
<action path="/editUser" ype="smarthings.webapp.action.UserAction" name="userForm" scope="request"
input="list" roles="admin" parameter="method" unknown="false" validate="false" >
<forward name="viewUsers" path="/editUser.html?method=Search( edit / save / delete )"/>
</action>
然后在Action中具体的实现Action都是继承了BaseAction的.比如
public final class PeopleAction extends BaseAction { //具体的操作方法search public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //具体的操作方法cancel public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {………} //具体的操作方法delete public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {………} //具体的操作方法Edit public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {……} ……… ……… |
相关文章推荐
- APPFUSE2使用说明及常见问题解决方法
- Struts2中Action接收参数的方法主要有以下三种:
- Struts2中Action接收参数的方法主要有以下三种:
- Java中Math类的一些主要方法
- Linux服务器CPU的一些主要指标说明
- Hibernate session的方法的一些说明
- 在ibatis中queryForPaginatedList( )方法的一些说明
- Kinect 1.8 体感开发,手势,姿态(Pose) 捕捉判断方法以及一些辅方法
- primary key与unique的区别 及 insert方法的一些说明注意
- android 没有main函数,怎么找到程序执行入口呢?以及activity主要生命周期的方法说明
- Rails源代码分析(40):ActionController Base的render方法
- LoadRunner 监控到的Linux服务器CPU的一些主要指标说明
- android中handler的一些总结以及使用(二)之handle使用时用到的几个主要方法介绍
- LatinIME中几个主要方法说明======》修改按键背景,以及行列间距
- Linux下判断内存使用的一些方法和说明【转】
- 图片异步加载框架 Android-Universal-Image-Loader的一些参数说明及方法
- 从AppFuse1.7的BaseAction中看DispatchAction的具体使用-转自dudutu
- JAVA-Spring-Aop拦截ACTION中的方法,但是运行时AOP会拦截我Action中所有的私有属性的一些get,set方法。
- LIBSVM使用方法及参数设置 主要参考了一些博客以及自己使用经验。
- QTP一个Test中生成多个Action的方法举例说明