开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜