Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails request.withFormat和动态搭建视图不起作用_Grails - Fatal编程技术网

Grails request.withFormat和动态搭建视图不起作用

Grails request.withFormat和动态搭建视图不起作用,grails,Grails,我已经配置了一个Grails应用程序来动态构建所有视图。在我的控制器中,我希望处理多种请求和响应内容类型,特别是html和json: request.withFormat { html { // do something } json { // do something else } } 查看2.2.x文档,我发现有request.withFormat可用于响应请求内容类型。对于来自我的自定义客户端应用程序的JSON请求,

我已经配置了一个Grails应用程序来动态构建所有视图。在我的控制器中,我希望处理多种请求和响应内容类型,特别是html和json:

request.withFormat {
    html { 
        // do something 
    }
    json { 
        // do something else 
    }
}
查看2.2.x文档,我发现有request.withFormat可用于响应请求内容类型。对于来自我的自定义客户端应用程序的JSON请求,这可以正常工作,但在为来自动态搭建视图的请求提供服务时,我的request.withFormat中定义的任何方法都不会匹配和执行


要使动态搭建的视图正确设置请求内容类型,我需要做一些特殊的事情吗?

启用以下功能:在config.groovy中

grails.mime.use.accept.header = true
见下表:

withFormat根据请求的格式工作-即Accept标头(如果已打开,格式=…查询参数等)。request.withFormat用于正文的内容类型嗯,是的,它用于。。。来自Grails文档:Grails忽略HTTP Accept头,除非您向Config.groovy文件添加Grails.mime.use.Accept.header=true设置。换句话说,withFormat()将完全不受没有该设置的Accept标头的影响。很抱歉,我在查看帖子时单击错误。我已添加此配置,但我的Accept标头仍被忽略。任何想法?request.WithFormat与访问标题无关。访问仅与WithFormat相关的标题(位不是请求。WithFormat)