1.表单提交失败的错误回显
2.合并Servlet
3.使用反射优化代码
package com.javaWeb;
import java.lang.reflect.Method;
public class testServlet {
public void login(){
System.out.println("login方法");
}
public void register(){
System.out.println("register方法");
}
public static void main(String[] args){
String action = "login";
try {
//通过action业务鉴别字符串获取相应的业务,方法反射对象
Method method = testServlet.class.getDeclaredMethod(action);
//System.out.println(method);
//调用目标业务方法
method.invoke(new testServlet());
} catch (Exception e) {
e.printStackTrace();
}
}
}
//输出
//login方法