容器在什么时候创建请求和响应对象?

At what point container creates request and response object?

当客户端请求到来时,容器根据URL找到正确的servlet,并创建一对请求和响应对象。

据我所知,请求和响应对象只有在容器找到有效的 servlet 时才会创建。也就是说,如果没有为所请求的 URL 找到有效的 servlet,则不会创建请求和响应对象。

但是,我不确定这一点。谁能确认一下。

12.1 URL 路径的使用 中,Servlet Specification 状态

The path used for mapping to a servlet is the request URL from the request object minus the context path and the path parameters.

因此我们可以假设请求对象(可能还有响应对象)是在执行任何映射逻辑之前创建的。

另请注意

Containers commonly recycle request objects in order to avoid the performance overhead of request object creation.