「Spring」コンテナエラーページ(Container Error Page)のサンプル

サンプルコード

@RestController
public class ErrorHandleController {

    @RequestMapping(path = "/error")
    public Map<String, Object> errHandle(HttpServletRequest request) {
        Map<String, Object> mp = new HashMap<String, Object>();
        mp.put("status", request.getAttribute("javax.servlet.error.status_code"));
        mp.put("reason", request.getAttribute("javax.servlet.error.message"));
        return mp;
    }
}

web.xml

<error-page>
    <location>/error</location>
</error-page>

 

SpringMVC

Posted by arkgame