Spring MVC 3:拦截器返回视图为false [英] Spring MVC 3: Interceptor return view on false

查看:201
本文介绍了Spring MVC 3:拦截器返回视图为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用拦截器来限制对应用中某些用户的访问。例如:

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.

推荐答案

它看起来像你可以在不命中servlet的情况下进行响应重定向。以下作品:

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;
    }

这篇关于Spring MVC 3:拦截器返回视图为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆