简体   繁体   English

Grails-在gsp中引用绝对URL

[英]Grails - Referencing Absolute URL in gsp

In my index.gsp for one of the column values for a table I provide the following: 在表的列值之一的index.gsp中,我提供了以下内容:

<td><g:link action = "redirect(url: 'http://www.google.com')">www.google.com</g:link></td>

However, the link that shows on the page is -> 但是,页面上显示的链接是->

http://localhost:8080/APP_NAME/VIEW_NAME/redirect(url: 'http://www.google.com')

What's the workaround to avoid the inclusion of the base url in the beginning. 有什么解决方法,可以避免一开始就包含基本网址。 I want the link to be the absolute URL -> 我希望链接是绝对URL->

http://www.google.com

Based on some of the comments below, the following works -> 根据以下一些评论,以下作品->

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

However, when I reference the field of a bean that I wish to display like this -> 但是,当我引用希望以这种方式显示的bean的字段时->

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

the link displays correct (www.google.com), while the actual link resolves to -> 链接显示正确(www.google.com),而实际链接解析为->

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

How do I eliminate the reference to the below Base URL? 如何消除对以下基本URL的引用?

http://localhost:8080/APP_NAME/

Use the tag anchor of the standard HTML 使用标准HTML的标记锚

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

EDIT 编辑

You can change: 你可以改变:

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

By: 通过:

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

It ignores the base attribute altogether, when encounter a protocol in front of the uri value. 当在uri值前面遇到协议时,它将完全忽略base属性。 Notice, it doesn't repeat http:// in the 2nd example, and used https:// instead, in the last one. 注意,在第二个示例中,它没有重复http:// ,而在最后一个示例中使用了https://

Moreover, you can specify target="_blank" , so page loads in a new tab or window. 此外,您可以指定target="_blank" ,以便页面加载到新的选项卡或窗口中。

NB: Should work for Grails 3.2 or >. 注意:应该适用于Grails 3.2或>。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM