【问题标题】:Access json file in web app folder from gsp grails?从gsp grails访问Web应用程序文件夹中的json文件?
【发布时间】:2013-05-02 21:34:51
【问题描述】:

我的 grails 应用程序的 web-app 文件夹中有一个名为flare.json 的 json 文件。

我在名为 reports the views 文件夹的文件夹中有一个名为 test.gsp 的 gsp。

我在 test.gsp 中有一个脚本,需要将 json 文件作为输入,但我似乎无法访问它。 我尝试了几种不同的方法,但到目前为止都没有运气。我正在查看的示例仅使用以下行:

d3.json("flare.json", function(error, data) { .....

我已经尝试过相同的变体和其他几种变体,但我不断收到 404 错误,提示找不到资源。我是 grails 的新手。我错过了什么吗?

【问题讨论】:

    标签: json web-applications grails gsp


    【解决方案1】:

    您可以尝试g.resource 为您的 json 文件创建链接。

    d3.json('${g.resource(file: "flare.json")}', function(error,data){});
    

    【讨论】:

    • 太棒了..我之前尝试过这种方法,但一定是格式错误..谢谢
    猜你喜欢
    • 2014-06-15
    • 2023-03-13
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    相关资源
    最近更新 更多