在我的 index.gsp 中,对于表的列值之一,我提供了以下内容:
<td><g:link action = "redirect(url: 'http://www.google.com')">www.google.com</g:link></td>
但是,页面上显示的链接是 ->
http://localhost:8080/APP_NAME/VIEW_NAME/redirect(url: 'http://www.google.com')
避免在开头包含基本 URL 的解决方法是什么。我希望链接是绝对网址 ->
http://www.google.com
根据下面的一些评论,以下作品->
<td><a href='http://www.google.com'>www.google.com</a></td>
但是,当我引用我希望像这样显示的 bean 字段时 ->
<td><a href=${fieldValue(bean: testRunInstance, field: "artifactLink")}>${fieldValue(bean: testRunInstance, field: "artifactLink")}</a></td>
链接显示正确 (www.google.com),而实际链接解析为 ->
http://localhost:8080/APP_NAME/www.google.com
如何消除对以下基本 URL 的引用?
http://localhost:8080/APP_NAME/
或者这个,如果你想要<g:link>
<g:link url="http://www.google.com">www.google.com</g:link>
使用标准 HTML 的标记锚点
<a href='http://www.google.com'>www.google.com</a>
编辑
您可以更改:
<td><a href=${fieldValue(bean: testRunInstance, field: "artifactLink")}>${fieldValue(bean: testRunInstance, field: "artifactLink")}</a></td>
由:
<td>
<a href="http://${testRunInstance.artifactLink}">
${fieldValue(bean: testRunInstance, field: "artifactLink")}
</a>
</td>
我认为您可以使用
<g:link url="http://www.google.com">www.google.com</g:link>
// Example, where artifactLink has a value, ddg.gg
<g:link base="http://" uri="${bean.artifactLink}">${bean.artifactLink}</g:link>
// Generates
<a href="http://ddg.gg">ddg.gg</a>
// Example, where artifactLink has a value, http://ddg.gg
<g:link base="http://" uri="${bean.artifactLink}">${bean.artifactLink}</g:link>
// Generates
<a href="http://ddg.gg">http://ddg.gg</a>
// Example, where artifactLink has a value, https://ddg.gg
<g:link base="http://" uri="${bean.artifactLink}">${bean.artifactLink}</g:link>
// Generates
<a href="https://ddg.gg">https://ddg.gg</a>
当遇到uri
值前面的协议时,它会完全忽略 base
属性。请注意,它在第二个示例中没有重复http://
,而是在最后一个示例中使用了https://
。
此外,您可以指定target="_blank"
,以便页面加载到新的选项卡或窗口中。
注意:应该适用于Grails 3.2或>。