gpt4 book ai didi

java - Spring中HTTP请求是如何解码的?

转载 作者:行者123 更新时间:2023-12-02 01:02:57 25 4
gpt4 key购买 nike

所以我的问题是我觉得没有得到太多解决,我的问题很简单,当服务器接收到 HTTP 消息(请求)时如何解码或处理(假设服务器正在运行 spring mvc)应用程序)?

为了将我的问题放在上下文中,假设客户端将一个简单的 HTTP 消息发送到服务器,HTTP 消息在哪里解码?从某种意义上说,在某些时候,某些逻辑或代码必须解析 HTTP 请求以查看其包含的内容,我的问题是此操作在哪里发生?这是调度程序 servlet 负责的事情吗?应用程序容器(即tomcat)负责解析/解码HTTP消息吗?如果是spring负责的,请给出解码HTTP消息涉及哪些类。

最佳答案

看起来Dispatcher servlet负责解码HTTP请求,特别是HttpServlet。根据this source (以及其他一些),Dispatcher Servlet 似乎有一堆子层:

enter image description here

HttpServlet class is, as the name suggests, the HTTP-focused Servlet implementation, also defined by the specification.

In more practical terms, HttpServlet is an abstract class with a service() method implementation that splits the requests by the HTTP method type.

有关 DispatcherServlet 的更多信息:

What we really want to do as developers of a web application is to abstract away the following tedious and boilerplate tasks and focus on useful business logic:

  • mapping an HTTP request to a certain processing method
  • parsing of HTTP request data and headers into data transfer objects (DTOs) or domain objects
  • model-view-controller interaction
  • generation of responses from DTOs, domain objects, etc.

The Spring DispatcherServlet provides exactly that.



PS:好问题!我使用 Spring 一段时间了,但从未真正质疑过如此详细的流程。感谢您让我走上这条路:)

关于java - Spring中HTTP请求是如何解码的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60422026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com