How do I return a 403 Forbidden in Spring MVC?

后端 未结 5 978
太阳男子
太阳男子 2020-12-29 03:14

I want my controller to return the right HTTP response code when the user lacks permission to view a particular page.

5条回答
  •  执念已碎
    2020-12-29 04:04

    Using an ExceptionResolver is a great way to go, but if you just want this to be view-independent, you could certainly make a call to response.sendError(HttpServletResponse.SC_FORBIDDEN, "AdditionalInformationIfAvailable"); in your Controller.

提交回复
热议问题