Matheus Eduardo Matheus Eduardo - 1 year ago 141
Java Question

Jersey redirect to a default URI when resource does not exist

I'm building a RESTful Web Service using Jersey 2.22, and I have the following scenario:

When I try to make a request to a path that does not exist (it's not implemented in the resources package at all), it'll send back a 404 status, because the resource wasn't found (obviously).

If this situation happens, I'd like to forward to a default URI, like sending back to index.html, for example.

But since it's a resource that is not implemented yet, where should I write this validation? Should it be in my class that extends from Application/ResourceConfig and has the @ApplicationPath annotation ? Could anyone show me a way or a documentation, or even a post that it's explicitly said?

Answer Source

You can handle 404 error code in your web.xml file -


Details can be referred to How to specify the default error page in web.xml?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download