Grails - how to access properties file from GSP

落爺英雄遲暮 提交于 2019-12-24 17:09:31

问题


I need to have access to my properties file from GSP file to get one of it's values. I tried to find example over the web, but I couldn't. This is a file which I created and not Grails.

Thanks!


回答1:


If the properties file is under grails-app/i18n/ (it can be your own properties file, doesn't have to be one of the default ones) then you can access property values from the property file in a GSP using the message tag. See http://grails.org/doc/latest/ref/Tags/message.html.




回答2:


you can access aaplicationContext from the GSP ... so you can access any configuration property.

Just look at this entry from Mr. Haki: http://mrhaki.blogspot.com.es/2011/11/grails-goodness-get-grailsapplication.html




回答3:


If you are reading simple properties it sounds like what you want is externalized configuration

To use it in a GSP (if you really need to, but not recommended from a GSP):

${Holders.config.myPropertyKey}


来源:https://stackoverflow.com/questions/23364829/grails-how-to-access-properties-file-from-gsp

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