3

I'm using an interceptor to restrict access to certain users in the app. For instance:

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
{
    Logger.logRequest(request);
    return list.contains(user);
}

If the list contains the user, it completes the request. Otherwise, it does nothing.

How do I display a custom page if the user doesn't have access? Right now, if it's false, it just shows a blank page which is not great for user experience.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Jason
  • 13,563
  • 15
  • 74
  • 125

1 Answers1

8

It looks like you can do a response redirect without hitting the servlet. The following works:

    if (list.contains(user))
        return true;
    else
    {
        //set up the view
        response.sendRedirect("nope_view");
        return false;
    }
Jason
  • 13,563
  • 15
  • 74
  • 125