java - SpringMVC using @ExceptionHandler HTTP Status 500 - Expected session attribute -
i use @exceptionhandler capture http status 500 - expected session attribute. return message same page on showing user error.
can point me example on how can handle exception , return message view instead of redirecting page.
this have far item in view not getting set error message;
@exceptionhandler(httpsessionrequiredexception.class) public redirectview handlehttpsessionrequiredexception(exception ex, httpservletrequest request) throws exception { logger.info("in handlehttpsessionrequiredexception handler method"); string referrer = request.getheader("referer"); redirectview redirectview = new redirectview(referrer); redirectview.addstaticattribute("errormessage","execute query retry"); return redirectview; }
view
<label id="errormessage" name="errormessage">${errormessage}</label>
you can referer , forward or redirect it. e.g.
@exceptionhandler(httpsessionrequiredexception.class) public string (httpservletrequest request) { string referrer = request.getheader("referer"); ... flashmap flashmap = requestcontextutils.getoutputflashmap(request); flashmap.put("errormessage","execute query retry"); return "redirect:/my/url"; }
the redirect url relative application path. can extract referer.
Comments
Post a Comment