Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails app root context

Tags:

grails

groovy

I have a test grails app setup with a context of "/testapp". When I add a link in my gsp that references / it does not go to the root of my grails.app.context, but to the root of my grails.serverURL property.

For example given a link with href "/css/main.css"

I would expect that this link would actually look in localhost:8080/testapp/css/main.css instead of localhost:8080/css/main.css

Is there a way that I can get references to / to start at my grails.app.context vs the grails.serverURL?

like image 389
ibuck Avatar asked Jul 19 '10 18:07

ibuck


2 Answers

use the request contextPath value on the page

${request.contextPath}

and then prepend the additional host information if necessary to construct the complete url

like image 80
Aaron Saunders Avatar answered Sep 28 '22 11:09

Aaron Saunders


the question is how do you add your links into your gsps?

We do things like

<link rel="stylesheet" href="${resource(dir: 'css', file: 'stylesheet1.css')}"/>

and

<g:javascript library="prototype"/>

by using the g:javascript and resource tags and methods, you tell grails to set the path for you...

I suspect you are just putting standard tags in...

goto

http://grails.org/doc/latest/

and, under tags in the left hand nav, look for resource and/or javascript to get an idea (its difficult to link directly in to the docs...:()

like image 40
hvgotcodes Avatar answered Sep 28 '22 13:09

hvgotcodes