java - Send Email or Logged Error on 404 and 500 Http Error Spring MVC -


I was thinking, it is possible to send me an email when my Spring MVC has a special HTTP error code. Please take a look at my web.xml configuration. It works fine and redirects me to the special error page.

  & lt; Web-App ... & gt; & Lt; Servlet & gt; & Lt; Servlet-name & gt; MVC-Despatcher & lt; / Servlet-name & gt; & Lt; Servlet category & gt; Org.springframework.web.servlet.DispatcherServlet & lt; / Servlet category & gt; & Lt; Load-On-Startup & gt; 1 & lt; / Load-on-startup & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; MVC-Despatcher & lt; / Servlet-name & gt; & Lt; URL pattern & gt; * Htm & Lt; / Url pattern & gt; & Lt; / Servlet-mapping & gt; & Lt; Error page & gt; & Lt; Error code & gt; 404 & lt; / Error code & gt; & Lt; Location & gt; /WEB-INF/pages/404.jsp< / Location & gt; & Lt; / Error page & gt; & Lt; Error page & gt; & Lt; Error code & gt; 500 & lt; / Error code & gt; & Lt; Location & gt; /WEB-INF/pages/500.jsp< / Location & gt; & Lt; / Error page & gt; & Lt; / Web application & gt;  

But what I want, I want to send an email or login to the event of this particular error. I was told in my first question that this type of error is not controlled by my controller hierarchy.

Any thoughts please?

For some reason, I did something like this works for my case Can You Comment? What are you doing? In my web.xml, I edited my location tag for forwarding it to my controller.

  & lt ;! - Error pages - & gt; & Lt; Error page & gt; & Lt; Error code & gt; 404 & lt; / Error code & gt; & Lt; Location & gt; /errorEncountered.htm< / Location & gt; & Lt; / Error page & gt; & Lt; Error page & gt; & Lt; Error code & gt; 500 & lt; / Error code & gt; & Lt; Location & gt; /errorEncountered.htm< / Location & gt; & Lt; / Error page & gt;  

In my controller, this is where I send an email.

  @Controller @RequestMapping ("/ errorEncountered.htm") public class ErrorHandlerController {Private MailService MailService; @RequestMapping (method = RequestMethod.GET) Public string handgate (HTTPSArlet request) {// CERTLE SPEC guarantees that this feature will be available throttle exception = (thrroyable) request .getAttribute ("javax.servlet.error.exception") ; . . . MailService.sendMail (); }}}  

Any criticism?


Comments