O'Reilly logo

Spring MVC Beginner’s Guide by Amuthan G

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – adding the response status exception

First, we will look at the @ResponseStatus annotation (org.springframework.web.bind.annotation.ResponseStatus). In Chapter 3, Control Your Store with Controllers, we created a request mapping method to display products by category under the URI template, http://localhost:8080/webstore/products/{category}. If no products were found under the given category, we would show an empty web page, which is not correct semantically. We should show an HTTP status error to indicate that no products exist under the given category. Let's see how we can do that with the help of the @ResponseStatus annotation:

  1. Create a class called NoProductsFoundUnderCategoryException under the com.packt.webstore.exception ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required