我正在使用grails 2.0.1,我尝试使用直接url ="somefile.html>链接到html页面,但它没有用.我怎么做?请帮助
你需要做两件事:
web-app/somefile.html,这是存储服务器的原始文件的位置.请使用g.resource()方法或<g:resource>标记,而不是使用硬编码的URL .在这些情况下,您将使用它:
<a href="${g.resource(file:'somefile.html')}">My Link</a>
Run Code Online (Sandbox Code Playgroud)使用g.resource标记的原因是它保证了与文件的正确链接.如果你只是硬编码文件href="somefile.html",那么是一个相对路径.如果您在URI myapp/controller/action/foo,它将在下面查找该文件myapp/controller/action/somefile.html.
注意:如果您使用的是cached-resources插件或类似的插件,您会发现输出URL实际上并非如此myapp/somefile.html.该文件仍可从该位置访问,但生成的链接将指向静态URL.