2014-02-18 39 views
1

引用绝对URL在我index.gsp中的列值之一表我提供以下信息:Grails的 - 在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的解决方法。我希望链接是绝对URL - >

http://www.google.com 

基于下面的一些评论,以下作品 - >

<td><a href='http://www.google.com'>www.google.com</a></td> 

然而,当我引用的领域豆,我希望这样显示 - >

<td><a href=${fieldValue(bean: testRunInstance, field: "artifactLink")}>${fieldValue(bean: testRunInstance, field: "artifactLink")}</a></td> 

链接显示正确(www.google.com),而实际的链接解析t o - >

http://localhost:8080/APP_NAME/www.google.com 

如何消除对以下基本URL的引用?

http://localhost:8080/APP_NAME/ 

回答

1

使用标准的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> 
+0

超级!!!您的建议完美无瑕。谢谢。 – chandragaajula

+0

@chandragaajula不客气。为了遵循StackOverflow规则,我建议你删除你的答案。 –

+0

删除我的答案。谢谢。 – chandragaajula

1

或此,如果你想<g:link>

<g:link url="http://www.google.com">www.google.com</g:link> 
+0

只是为了好奇:如果我们这样做。解析gsp到html有一个性能影响(显然是最小的)? –

+1

虽然存在,但与应用程序的其他所有区域相比,它非常小,当您分析应用程序并寻找瓶颈时,它甚至不会显示出来。 –

0

我认为你可以使用

 <g:link url="http://www.google.com">www.google.com</g:link> 
+0

您的建议会导致链接 - >“http:// localhost:8080/APP_NAME/VIEW_NAME/redirect(url:www.google.com,absolute:true)” – chandragaajula

+0

您的“动作”参数肯定有问题。只需使用锚点或g:link的url参数即可 –

0
// 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> 

它忽略了base共有属性,当遇到一个协议在uri值的前面。注意,在第二个例子中它不重复http://,而在最后一个例子中使用https://

此外,您可以指定target="_blank",因此页面会加载到新标签页或窗口中。

注意:应该适用于Grails 3.2或>。