(@Context HttpServletResponse response not work in resteasy
java, servlets, web
Solution
RESTEasy is interpreting your method as best it can - you didn't specify a return type so it returns a 204 (No Content) back to the client. A void `GET` method really does not make alot of sense and should be avoided, or converted into another HTTP verb (like POST).
On topic, this is not the right way to set the status of responses from JAX-RS calls. You should use the ResponseBuilder instead.
Response.status(202).build();
You can of course, use the injected `HttpServletResponse` for any other thing as long as it makes sense within the context of the call:
response.setHeader("Location", "http://www.example.com/myresource/5");
Problem
Web application with resteasy framework. ``` @Path("/do3") @GET public void response(@Context HttpServletResponse response) throws IOException{ response.setStatus(202); } ``` why get /do3 return 204, not 202? Thanks in advance. PS: (1) I switch to @post method. it also can't get expected code: 202 by get. (2) response.addHeader("key", "value"); can work normally.