KunLun
KunLun

Reputation: 3225

Spring customize error page return no explicit mapping for /error

I want to customize error page from spring like this:

@Controller
public class Error implements ErrorController{

    @RequestMapping(value = "/error")
    public ModelAndView error(){

        return new ModelAndView("error");

    }

    @Override
    public String getErrorPath(){
        return "/error";
    }

}

ModelAndView("error") - error is an jsp in WEB-INF/jsp/

When I try to trigger error by accessing an invalid link: mydom.com/invalidlink is not printed my error.jsp.

Insted is printed this message:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

null
There was an unexpected error (type=null, status=null).

How I customize error page?

Upvotes: 0

Views: 206

Answers (1)

Istiaque Hossain
Istiaque Hossain

Reputation: 2357

i post my code for your help

@Controller
public class CustomErrorController implements ErrorController  
    @RequestMapping("/error") 
    public String handleError(HttpServletRequest request, Model model) { 
        return "error";
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}

my code is working , there is only one difference between your and my code

public String handleError()

it's return string and your case

public ModelAndView error()

return ModelAndVIew.....

Upvotes: 1

Related Questions