如何忽略过滤器回传电话 [英] How to ignore filter for postback calls

查看:148
本文介绍了如何忽略过滤器回传电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个过滤器,它需要一个ID参数(GET)。这工作得很好,当我的导航链接添加参数。但是,当我住在同一个站点(如AJAX调用),过滤喊声和尖叫声,因为ID参数丢失。

I have a filter which requires an id-parameter (GET). This works fine when I add the parameter in the navigation links. But when I stay at the same site (e.g. ajax calls), the filter shouts and screams, because the id-parameter is lost.

有机会忽略过滤器,如果请求来自阿贾克斯? 像

Is there a chance to ignore the filter if the request come from ajax? something like

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (FacesContext.getCurrentInstance().isPostback()) {...}
    ...
}

推荐答案

我找到了解决办法,工作正常。

I found a solution which works fine

private boolean isAJAXRequest(HttpServletRequest request) {
    boolean check = false;
    String facesRequest = request.getHeader("Faces-Request");
    if (facesRequest != null && facesRequest.equals("partial/ajax")) {
        check = true;
    }
    return check; 
}

在过滤的开始,只是将它加入这样的:

in the beginning of the filter, just add it like:

@Override 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;

    if(isAJAXRequest(req)){
        System.out.println("IGNORE THIS FILTER, AJAX");
        chain.doFilter(request, response);
        return;
    }
    ...
}

这篇关于如何忽略过滤器回传电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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