2012-02-22 143 views

回答

3

尝试

createLink(absolute : 'true') 

这应该指向http://localhost:8080/yourproject/(缺省设置)

+1

这就是我想的,但它并没有做到这一点。使用Grails 1.3.7和2.0.1,创建一个新的应用程序并生成一个名为“Info”的控制器,并使用def index = {render createLink(absolute:'true')},我看到这个:http://本地主机:8080/MyProject的/信息/索引。 – 2012-02-23 02:40:38

+1

从你的gsp中,你也可以在正常的'' – ccheneson 2012-02-23 07:58:00

28

您可以指定uri'/'的:

<a href="${createLink(uri: '/')}">link text</a> 
+0

That drops the host and protocol information. – 2012-02-23 03:09:59

+2

Right - it's relative to the running app. If you need a link that works outside of the app make it absolute: 'link text' – 2012-02-23 05:14:50

+0

中使用'$ {request.contextPath}'是的,在一个更清晰的时刻,我刚刚意识到这一点,然后在这里检查。今天会尝试,谢谢! – 2012-02-23 10:51:23

4

我用这个代码:

<g:link uri="/">Home</g:link>