简体   繁体   中英

Changing grails.serverURL has no effect on createLinkTo( […], absolute:'true')?

I'm trying to display a Java applet in a page on a Grails server. I'm using Sun's handy Javascript snippet for displaying applets:

<script src="http://java.com/js/deployJava.js"></script>
<script>
deployJava.runApplet({codeBase:"${createLinkTo(dir:'applet', absolute:'true')}",
    archive:"${createLinkTo(dir:'com/steve/applet', file='applet.jar', absolute:'true')}",
    code:"com.steve.Applet.class",
    width:"500", height:"500"}, null, "1.5");
</script>

In Config.groovy, I set up the different serverURLs:

environments {
    production {
        grails.serverURL = "http://10.0.xx.xxx/"
    }
    development {
        grails.serverURL = "http://10.0.yy.yyy:8080/"
    }
}

However, the links created by createLinkTo() all have " http://localhost:8080 " instead of the URL I specified. (ie they look like " http://localhost:8080/my-app/applet ".) Is this a bug? Is there a workaround?

I found a workaround. Instead of using createLinkTo, I just defined a new variable in Config.groovy:

environments {
    development {
        grails.appURL = "http://10.0.xx.xxx:8080/my-app"
    }   
    production {
        grails.appURL = "http://10.0.yy.yyy"
    }
}

In my code, I do this: import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH

//...
def appURL = CH.config.grails.appURL
//...

This at least lets me get a predictable path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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