Announcement Announcement Module
Collapse
No announcement yet.
Spring 2.5 MVC controller returning only Http status codes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 2.5 MVC controller returning only Http status codes

    Hi,
    I would like to return only Http status codes when a controller is called. I do not need any view.
    Is there any elegant way of doing it ?
    I have done like this

    @Controller
    public class PurchaseController {
    ...

    @RequestMapping("/purchase")
    public void createPurchase(@RequestParam("productPk") Long productPk,
    Model model, HttpServletResponse response) {

    try {
    webServiceFacade.createPurchase(productPk);
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentLength(0);

    } catch (Exception e) {
    LOG.error(ExceptionUtils.getStackTrace(e));
    response.setStatus(HttpServletResponse.SC_INTERNAL _SERVER_ERROR);
    response.setContentLength(0);
    }

    }

    Is this the correct approach?

    Chakra

  • #2
    Spring 2.5 MVC controller returning only Http status codes

    Spring 3.0 has an elegant way of to return http status codes using ResponseStatus annotation. A controller handler method or an exception class can been annotated with ResponseStatus to return relevant status codes.

    Regards,
    Deepan Subramani.

    Comment


    • #3
      I cannot find the documentation for the @ResponseStatus annotation. It is not mentioned at all in the "Spring Framework Reference Manual". Am I missing an important part of the documentation?

      Stefan

      Comment

      Working...
      X