0

I'm trying to handle a HTTP Status Error 400. I think that this occurs due to a type mismatch. So e.g.
http://localhost:8080/app/info.htm?id=123 works while
http://localhost:8080/app/info.htm?id=abc doesn't.

@RequestMapping(value = "/info", method = RequestMethod.GET, params = "id")
public String getInfo(@RequestParam("id") Integer id, Model model) {
    // get info object via service and show it
    // model.addAttribute("infoObj", infoObj);

    return "info";
}

Is there a way to handle this and return e.g. the page index.jsp if this error occurs?

2
  • Capture id using Object Commented Jun 25, 2015 at 18:35
  • Okay, that could be a way, but I think that this would be very inelegant because basically you could do this at every controller mapping using never inherited classes. Commented Jun 26, 2015 at 6:40

1 Answer 1

1

From what I understand that 400 error is that The request could not be understood by the server due to malformed syntax. That means id works good with int but not strings.

It does have the way that allows you to redirect the page to a certain page if error happned.

you need do some configs in web.xml file. you can do as follows:

<error-page>

    <error-code>400</error-code>
    <location>/index.html</location>
</error-page>
Sign up to request clarification or add additional context in comments.

1 Comment

After restarting the server several times, this worked for me now , thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.