1
votes

in the Spring MVC Showcase example dowlodable from the STS dashboard

I have some doubt about the following situation:

In my view I have the following link:

        <li>
            <a id="responseEntityStatus" class="textLink" href="<c:url value="/response/entity/status" />">ResponseEntity (custom status)</a>           
        </li>

This link generate an HTTP Request towards the URL: "/response/entity/status"

This URL is handled by the following method of a @Controller class named ResponseController (which in turn is annotated with @RequestMapping(value="/response", method=RequestMethod.GET) )

The method thath handled the previus HTTP Request is:

@RequestMapping("/entity/status")
public ResponseEntity<String> responseEntityStatusCode() {
    return new ResponseEntity<String>("The String ResponseBody with custom status code (403 Forbidden)",
            HttpStatus.FORBIDDEN);
}

This method return a ResponseEntity object and, reading the documentation, I understand that returning a setted ResponseEntity objct is substantially the same thing as a return a @ResponseBody String object

So, in my particular case, I am returning a ResponseEntity object (that rappresent my HTTP Response) in wicht I have setted the

  1. HTTP RESPONSE Body field with the String The String ResponseBody with custom status code (403 Forbidden)

  2. I have not setted Headers fields

  3. I have setted the HTTP Status status code to HttpStatus.FORBIDDEN

Now, I have read that this HttpStatus is a field of ResponseEntity class but I have not understand what this object exactly rappresent...

So what rappresent the HttpStatus object? and what mean if it is setted to FORBIDDEN?

1

1 Answers

2
votes

HttpStatus is not an object, it's a Enum that contains an enumeration of HTTP status code. The FORBIDDEN status represent the HTTP 403 status code