Can you please provide any pointers to how to gracefully display maintenance message in case of shutting down the server, instead of error message displayed to the client? Seems like I need another server in front.
Indeed you do. A typical configuration for a web app might be to have a web server (such as Apache HTTP Server) in front of the servlet container which serves static content. If there is, then you can just serve your "appliction not available" page here.