如何使用<a> tag?

时间:2015-10-29 02:42:15

标签: grails

This is my first Grails project & I can't seem to do this very simple thing! I am trying to display a list of PDF forms in one page that I have saved under a folder called forms under my_project/grails-app/views/forms and want to open the PDF form in a new window when clicked.

In my .gsp file I am trying to access the forms like this:

<a href="${resource(dir:'forms',file:'form_one.pdf')}" target="_blank">Form #1</a>

But that's giving me a 404 error.

I have found couple of solutions like this onethis question(与我的非常相似)从Grails应用中打开文件...但首先,我不需要上传/下载文件。其次,我也不需要渲染文件。我想要做的只是单击链接并在新窗口/选项卡中打开PDF文件。我是否将PDF文件保存在错误的位置?请帮忙!!谢谢。

1 个答案:

答案 0 :(得分:3)

将您的文件/目录放入grails-app/assets,以便grails-app/assets/forms/form_one.pdf然后您可以使用resource标记,如下所示:

<a href="${resource(dir: 'forms', file: 'form_one.pdf')}" target="_blank">Form #1</a>

grails-app/views目录用于控制器呈现的视图,其中grails-app/assets目录用于静态和预处理资产。