0

I am working on dropwizard-Java project.I am trying to create my own custom page for 404 error. I have the coded till,a blank page showing a given string.

@Path("/{default: .*}")
public class DefaultErrorPage implements ContainerResponseFilter {
    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {

        if (responseContext.getStatus() == 404) {
            responseContext.setEntity("This page is not found");

        }
    }

But I needed to return a html page when it shows 404 error.If anyone knows,please help me to solve.

user57
  • 136
  • 1
  • 3
  • 15
  • 1
    Possible duplicate of: http://stackoverflow.com/questions/36401838/how-do-i-override-all-404-pages-without-defining-default-handlers-for-every-reso/36408241#36408241 – pandaadb May 20 '16 at 09:54
  • sorry..I didn't understand clearly about error handlers,where to overwrite,and how can I call my own default html page. – user57 May 20 '16 at 10:14
  • The thing with 404 is that they never reach your filters. They do not get routed through, because the path they need to be routed to don't exist. Jetty knows this, because it knows your jersey resources. You need to hook into jetty to overrride the default 404 page. You can look at the ErrorHandler implementation in the jetty source to see how they create the html response. See the method: writeErrorPage – pandaadb May 20 '16 at 10:38

0 Answers0