File tree Expand file tree Collapse file tree
java/com/baeldung/errorhandling/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,19 +15,21 @@ public MyErrorController() {}
1515
1616 @ RequestMapping (value = "/error" )
1717 public String handleError (HttpServletRequest request ) {
18-
19- Integer statusCode =
20- Integer .valueOf (request .getAttribute (RequestDispatcher .ERROR_STATUS_CODE ).toString ());
21-
22- if (statusCode == HttpStatus .NOT_FOUND .value ()) {
23- return "error-404" ;
24- }
25- else if (statusCode == HttpStatus .INTERNAL_SERVER_ERROR .value ()) {
26- return "error-500" ;
27- }
28- else {
29- return "error" ;
18+
19+ Object status = request .getAttribute (RequestDispatcher .ERROR_STATUS_CODE );
20+
21+ if (status != null ) {
22+
23+ Integer statusCode = Integer .valueOf (status .toString ());
24+
25+ if (statusCode == HttpStatus .NOT_FOUND .value ()) {
26+ return "error-404" ;
27+ }
28+ else if (statusCode == HttpStatus .INTERNAL_SERVER_ERROR .value ()) {
29+ return "error-500" ;
30+ }
3031 }
32+ return "error" ;
3133 }
3234
3335 @ Override
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html >
3+ < head >
4+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css " integrity ="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm " crossorigin ="anonymous " />
5+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css " />
6+ </ head >
37< body >
4- < h1 > Sorry we couldn't find the resource you are looking for</ h1 >
5- < a href ="/ "> Go Home</ a >
8+ < div class ="container ">
9+ < div class ="jumbotron " >
10+ < h1 class ="text-center "> < i class ="fa fa-frown-o "> </ i > Sorry, we couldn't find the page you were looking for. </ h1 >
11+ < p class ="text-center "> < a class ="btn btn-primary " href ="/ "> < i class ="fa fa-home "> </ i > Go Home</ a > </ p >
12+ </ div > </ div >
613</ body >
7- </ html >
14+ </ html >
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html >
3+ < head >
4+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css " integrity ="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm " crossorigin ="anonymous " />
5+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css " />
6+ </ head >
37< body >
4- < h1 > Oops! We spilled something but we're fixing it</ h1 >
5- < a href ="/ "> Go Home</ a >
8+ < div class ="container ">
9+ < div class ="jumbotron " >
10+ < h1 class ="text-center "> < i class ="fa fa-frown-o "> </ i > Sorry, something went wrong! </ h1 >
11+
12+ < h2 class ="text-center "> We're fixing it.</ h2 >
13+ < p class ="text-center "> < a class ="btn btn-primary " href ="/ "> < i class ="fa fa-home "> </ i > Go Home</ a > </ p >
14+ </ div > </ div >
615</ body >
7- </ html >
16+ </ html >
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html >
3+ < head >
4+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css " integrity ="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm " crossorigin ="anonymous " />
5+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css " />
6+ </ head >
37< body >
4- < h1 > Something went wrong! Our Engineers are on it temp</ h1 >
5- < a href ="/ "> Go Home</ a >
8+ < div class ="container ">
9+ < div class ="jumbotron " >
10+ < h1 class ="text-center "> < i class ="fa fa-frown-o "> </ i > Something went wrong! </ h1 >
11+
12+ < h2 class ="text-center "> Our Engineers are on it.</ h2 >
13+ < p class ="text-center "> < a class ="btn btn-primary " href ="/ "> < i class ="fa fa-home "> </ i > Go Home</ a > </ p >
14+ </ div > </ div >
615</ body >
716</ html >
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments