This GSP:
<g:link controller="book" action="show" id="5">Example</g:link>
results in this HTML:
<a href="/book/show/5">Example</a>
This is relative to the HTTP host. If your site is running at http://localhost:8080 that's fine.
During development, an app will more commonly be running at http://localhost:8080/appName.
In such cases, the above link will not work - it will result in an absolute URL of http://localhost:8080/book/show/5 instead of the required http://localhost:8080/appName/book/show/5
What changes are required of the above GSP for the app name to be present in the resulting anchor's href?
The configuration setting grails.app.context
should be equal to the context where you want your application deployed. If it's not set, as in the default configuration, it defaults to your application name, like http://localhost:8080/appName
. If you want to deploy your app in the root context (e.g. http://locahost:8080/
), add this to your Config.groovy
:
grails.app.context = "/"
If the context is properly set, the URLs generated by g:link
tags will include the context before the controller name.