views:

40

answers:

1

Hi.

I want handle update operation using SimpleFormController. URL to this controller looks as follow:

http://example.com/updatesomething.html?id=42

I wonder how to validate on the begining if object with the given id (42) exists, because I want display 404 error page when id is incorrect and stop processing.

Thanks in advance for your answers.

A: 

You should put in your method the attribute HttpServletResponse response like this

public void handleRequest(Long id, HttpServletResponse response) {
  if(!objectExists(id) {
    response.sendError(HttpServletResponse.SC_NOT_FOUND);
  }
  //do stuff
}
Daniel Moura