简体   繁体   English

Play框架Global.java中的多个过滤器

[英]Play Framework Multiple filters in Global.java

I'm using Play Framework 2.3.2 (Java version) 我正在使用Play Framework 2.3.2(Java版)

I was wondering how I would go about adding multiple filters to the filters() override in Global.java? 我想知道如何在Global.java中为过滤器()覆盖添加多个过滤器? I have this to enable the CSRF Filter: 我有这个启用CSRF过滤器:

public class Global extends GlobalSettings {
    @Override
    public <T extends EssentialFilter> Class<T>[] filters() {
        return new Class[]{CSRFFilter.class};
    }
}

and I'd like to now also add the Gzip filter. 我现在还要添加Gzip过滤器。 What's the correct syntax to use to have both the CSRF filter and GZIP compression? 使用CSRF过滤器和GZIP压缩的正确语法是什么? It's described here: http://www.playframework.com/documentation/2.3.x/GzipEncoding but it doesn't say how to add that as a filter when one already exists. 它在这里描述: http//www.playframework.com/documentation/2.3.x/GzipEncoding但它没有说明如何在已经存在的情况下将其添加为过滤器。

Thanks in advance! 提前致谢!

You can add them in the array like 你可以在数组中添加它们

return new Class[]{CSRFFilter.class, GzipFilter.class};

Unfortunately I didn't find any info about the order they are executed, but I guess they are executed in the order they are defined in the array. 不幸的是我没有找到关于它们执行顺序的任何信息,但我猜它们是按照它们在数组中定义的顺序执行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Play Framework 2.X:使用onReqest处理并在Global.java中重定向 - Play Framework 2.X : Dealing w/ onReqest and redirect in Global.java 因此,当我将代码部署到CloudBees global.java时将无法运行(Play Framework 2.1) - So when I deploy my code to CloudBees global.java won't run (Play Framework 2.1) Java Play框架全局变量 - Java Play Framework Global Variables 播放框架java 2.3.7中的全局异常处理 - Global Exception Handling in play framework java 2.3.7 使用过滤器和操作在play框架中获取请求主体。(在Java中) - Get the request body in play framework using filters and actions.(in java) 将playframework升级到2.4.6后,Global.java的onstart方法执行了两次 - onstart method of Global.java getting executed twice after upgrading playframework to 2.4.6 如何处理Play Framework 2(Java)中表单的全局错误 - How to handle global errors in forms in Play Framework 2 (Java) 执行其他控制器方法的JPA.withTransaction方法错误:Global.java:39:错误:此处不允许使用“无效”类型 - JPA.withTransaction executing other controllers method error: Global.java:39: error: 'void' type not allowed here 缺少包&#39;play.filters.cors.CORSFilter&#39; - Play Framework 2.4.6(Java) - Missing package 'play.filters.cors.CORSFilter' - Play Framework 2.4.6 (Java) Play 2的多个全局设置 - Multiple Global Settings for Play 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM