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 one或this question(与我的非常相似)从Grails应用中打开文件...但首先,我不需要上传/下载文件。其次,我也不需要渲染文件。我想要做的只是单击链接并在新窗口/选项卡中打开PDF文件。我是否将PDF文件保存在错误的位置?请帮忙!!谢谢。
答案 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
目录用于静态和预处理资产。