`
dd350356750
  • 浏览: 73695 次
  • 性别: Icon_minigender_1
  • 来自: 怀化
社区版块
存档分类
最新评论

struts_DispatchAction的实现

阅读更多
package com.dd.struts.actions;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


/*
 * org.apache.struts.actions.DispatchAction;
 * 类的低层实现 
 * */
public class DispachActions extends Action{

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//获得struts_config.xml 配制文件action-mappings 里面的parameters 的value
		String params = mapping.getParameter();
		
		//通过params 获得界面上对应名称的value值
		String method = request.getParameter(params);
		
		//表示当前类对象.Servlet初始了哪个类就是哪个类的对象 在这里是 DispachActions的子类的对象
		//不本类的对象
		Class c = this.getClass();
		
		Method mh = c.getMethod(method, new Class[]{ActionMapping.class,ActionForm.class,HttpServletRequest.class,HttpServletResponse.class});
		Object obj = mh.invoke(this,mapping,form,request,response);
		return (ActionForward) obj;
	}	
}


DispatchAction 简单的DispatchAction实现.不到的地方希望指点

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics