[英]Grails - Referencing Absolute URL in gsp
在表的列值之一的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/
使用標准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>
<g:link url="http://www.google.com">www.google.com</g:link>
我認為你可以使用
<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或>。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.