link directly to GSP

无人久伴 提交于 2019-12-03 02:12:20

The createLink tag is geared for use with controller actions and won't do what you want it to outside of the url attribute.

You can always get to a gsp by directly: /user/foo.gsp with a combination of the link and resource tags.

<g:link url="${resource(dir:'user', file:'foo.gsp')}">user/foo.gsp</g:link>

Othewise you can create a URL Mapping that maps a request directly to a view.

class UrlMappings {
    static mappings = {
        "/user/foo"(view:"user/foo")
    }
}

Using Grails 1.2 you can create a named URL Mapping that maps directly to a view:

class UrlMappings {
    static mappings = {
        name userFoo: "/user/foo"(view:"user/foo")
    }
}

and then use it with the link tag:

<link:userFoo>User Foo</link:userFoo>

or

<g:link mapping="userFoo">User Foo</g:link>

There's a uri attribute that's undocumented , but you can see it in the source:

<a href="${createLink(uri:'/path/page.gsp')}">link</a>

HTH

As of Grails 2.x, this is not possible. The ability to link directly to a .gsp was a security flaw that could be used to avoid the @Secured annotation. The URL mapping method does still work though as seen in @Colin Harrington's answer.

See: GRAILS-7542: Views are accessible via a URL pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!