覆盖 Struts 应用程序中的默认 ResourceBundle
我有一个属性文件,它捆绑在 WEB-INF/lib 中的外部 jar 文件中。如果我想覆盖该属性文件中的值并使用我自己的属性文件中的值。有没有更好的方法来做到这一点。 例如: 在默认属性文件中,我看到
banner.ad.link=<a href="{1}" title="Click here {0}">{0}</a>
我想将其更改为类似以下内容:
banner.ad.link=<a class="mycss" href="{1}" title="Click here {0}">{0}</a>
到目前为止,这就是我所拥有的:
public class MainListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event)
{
ResourceBundle bundle = ResourceBundle.getBundle("com.comResources");
bundle = ResourceBundle.getBundle("org.displaytag.messages",
Locale.getDefault());
for (Enumeration<String> e = bundle.getKeys(); e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}
}
}
我不太确定从这里到哪里去覆盖捆绑对象中的键值对以获得新的我自己的属性文件中的值。任何帮助,我将不胜感激!提前致谢!
I have a property file that is bundled in an external jar file in my WEB-INF/lib. If I want to override the values in that property file and use my own values from my own property file. Is there a better way to do it.
For example:
in the default property file, I see
banner.ad.link=<a href="{1}" title="Click here {0}">{0}</a>
I want to change it to something like:
banner.ad.link=<a class="mycss" href="{1}" title="Click here {0}">{0}</a>
So far this is what I have:
public class MainListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event)
{
ResourceBundle bundle = ResourceBundle.getBundle("com.comResources");
bundle = ResourceBundle.getBundle("org.displaytag.messages",
Locale.getDefault());
for (Enumeration<String> e = bundle.getKeys(); e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}
}
}
I'm not too sure where to go from here to override the key value pair from the bundle object to have a new value from my own property file. Any help, I would be greatly appriciated! Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到了三种方法。
请注意,如果您只想自定义 displaytag,则只需将 displaytag.properties 放在类路径的根目录中(即默认包中),而不是放在
org.displaytag.properties
包,如此处所述。如果找到,Displaytag 将加载您的捆绑包而不是默认捆绑包。I see three ways of doing it.
Note that if all you want to do is to customize displaytag, you just have to put your displaytag.properties at the root of the classpath (i.e. in the default package) rather than in the
org.displaytag.properties
package, as documented here. Displaytag will load your bundle rather than the default one if found.