I'm writing a REST web application (NetBeans 6.9, JAX-RS, and TopLink Essentials) and trying to return JSON and HTTP status code. I have code ready and working that returns JSON content when the HTTP GET method is called from the client.
Essentially:
@Path("get/id")
@GET
@Produces("application/json")
public M_機械 getMachineToUpdate(@PathParam("id") String id) {
// Some code to return JSON content ...
return myJson;
}
But I also want to return an HTTP status code (500, 200, 204, etc.) along with the JSON data.
I tried to use HttpServletResponse:
response.sendError("error message", 500);
But this made the browser think it was a "real" 500, so the output web page was a regular HTTP 500 error page.
I want to return an HTTP status code so that my client-side JavaScript can handle some logic depending on it (to, e.g., display the error code and message on an HTML page). Is this possible or should HTTP status codes not be used for such a thing?