forEach遍历map集合
由xml解析出类名和方法名执行该方法:
HelloAction类:
public class HelloAction { public String hello(){ System.out.println("ms future"); return "success"; } }
对应的xml文件:
<package name="hello" namespace="/hello" extends="struts-default" > <action name="HelloAction" class="cn.itheima.a_hello.HelloAction" method="hello" > <result name="success" type="dispatcher" >/hello.jsp</result> </action> </package>
执行过程:
public static void main(String[] args) throws Exception { Class clazz = Class.forName("class com.future.ms.HelloAction"); HelloAction helloAction = (HelloAction) clazz.newInstance(); Method method = clazz.getMethod("hello", null); method.invoke(helloAction, null); }