package com.test.classobject;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.test.pojo.Student;
@WebServlet("/TestServlet4")
public class TestServlet4 extends HttpServlet {
private static final long serialVersionUID = 1L;
public TestServlet4() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Class clazz=Student.class;
Student student=new Student();
try {
Method method= clazz.getDeclaredMethod("test", String.class,int.class);
method.invoke(student, "zhangsan",23);
Method method2=clazz.getDeclaredMethod("test", int.class);
Object o=method2.invoke(student, 25);
System.out.println(o.toString());
} catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}