开发者

How do I add an extension to the response name returned from a grails render method?

开发者 https://www.devze.com 2023-01-11 07:01 出处:网络
I am trying to develop a grails application that returns kml (to be viewed in Google Earth) using the controller code snippet below.

I am trying to develop a grails application that returns kml (to be viewed in Google Earth) using the controller code snippet below.

render(contentType: "application/vnd.google-earth.kml+xml", 
   view:"kml", 
  model:[feeds: feeds, feedColors: feedColors]);

This works great...but Google Earth does not open the response until it is first saved to disk and renamed with a '.kml' extension. This is very annoying and will greatly limit the use of my web application.

开发者_开发知识库

How do I add the .kml extension to the response name returned from grails render method?


I think this will work:

response.setHeader("Content-disposition", "attachment; filename=${filename}.kml");
render(contentType: "application/vnd.google-earth.kml+xml", 
   view:"kml", 
  model:[feeds: feeds, feedColors: feedColors]);
0

精彩评论

暂无评论...
验证码 换一张
取 消