HttpServletResponse response
时间: 2023-10-16 22:26:38 浏览: 71
`HttpServletResponse` is an interface in the Java Servlet API that defines the response that a servlet sends back to the client. It provides methods for setting response headers and writing response content, such as HTML, XML, or JSON.
For example, you can use the `setContentType` method to set the MIME type of the response content, and then use the `getWriter` method to get a `PrintWriter` object and write the content to the response.
Here is an example of creating a simple HTTP response with a status code of 200 OK and some text content:
```
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
PrintWriter out = response.getWriter();
out.println("Hello, world!");
```
阅读全文