# HttpServletReflect
**Repository Path**: zhandsome/HttpServletReflect
## Basic Information
- **Project Name**: HttpServletReflect
- **Description**: ★ 面试题:一个请求发送到服务器,服务器是如何做出响应的?
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-11-02
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# HttpServletReflect
★ 面试题:一个请求发送到服务器,服务器是如何做出响应的?
HTML页面:发送请求
web.xml:
ReflectServlet
ReflectServlet
com.zs.reflect.HttpReflectServlet
ReflectServlet
/hello
Apache根据请求hello,解析xml获得元素的Text,即字符串“com.zs.reflect.HttpReflectServlet”。
① 获得Class
Class> c= Class.forName("org.wdl.servlet.HelloServlet");
② 获得响应的Servlet的实例
Object obj = c.newInstance();
③ 调用Servlet实例的名称为“service”的Method
Method method =c.getDeclaredMethod("service",HttpServletRequest.class,HttpServletResponse.class);
④ 调用方法,使用request对象和response对象做参数
注意:当请求到服务器的时候,服务器就会创建request对象和response对象。
method.invoke(obj,request,response);