lundi 30 mars 2015

How to display a HTTP status code of a url (For example, 404, 200, etc. ) on Spring's JSP page?

I need to display a HTTP status code like 404, 200, 500, etc. of a url on a jsp page in Spring MVC. I have tried to read a lot of the online documentations but a lot of them do not show you how to exactly do it and get it displayed on a jsp page.


I have my controller like this:



@Controller
public class HomeController {

@ResponseStatus(HttpStatus.BAD_REQUEST)

@ResponseBody ErrorInfo handleBadRequest(HttpServletRequest req, Exception ex) {
return new ErrorInfo(req.getRequestURL(), ex);
}
}


And my jsp:



<p>The error is : ${ex} </p>


And also tell me what kind of Maven dependency I need in my pom.xml file.


Thanks!


Aucun commentaire:

Enregistrer un commentaire