Hello.

When writing a project, a question on a topic appeared which I didn’t really think about.

And what is the actual difference between Response, ServletResponse, HttpServletResponse?

    1 answer 1

    HttpServletResponse

    Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response. For example, HTTP headers and cookies.

    It is assumed that the servlet technology is not tied to only http. Although the masses are not known about other “bindings”, even if they exist.

    Therefore, a ServletResponse is some abstract response of some abstract Servlet.
    And HttpServletResponse is a specific such ServletResponse of a specific HttpServlet.

    What kind of Response to this company recorded absolutely not clear. Therefore, we will assume that this word means exactly what it means - any answer / response (of which (anyone) or to something).
    As applied to servlets, as classes of existing entities are refined, they are first converted to ServletResponse, and then to HttpServletResponse.

    • So that means turning? When creating the response "Response" and the return is valid in any method, this response and the information in it reaches the browser (client)? How does this transformation go there? - Maks.Burkov 5:46 pm
    • @ Maks.Burkov I kind of made it clear that I do not understand what kind of Response in question. I do not know any Response in the servlet response hierarchy. Therefore, all that relates to your Response is a joke with a bit of truth. Responsa are used everywhere where they are not. Therefore, it is not clear what kind of speech - nothing concrete can be said. - Sergey
    • docs.oracle.com/javaee/7/api/javax/ws/rs/core/Response.html Oh well, everything is clear .. Look at the documentation. The main thing without nerves! - Maks.Burkov
    • This Response from the RESTful API is completely different from the ServletResponse from the Servlet API. - Sergey
    • REST usually functions as a servlet. But the programmer is given a completely different API. Based on the Response built by you, the REST framework itself fills the HttpServletResponse as it sees fit. - Sergey