2014-02-18 44 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或>。