问题描述
从过去的年份开始,我们开发了一个应用程序,其中我们使用静态字符串常量来存储常量。
喜欢
公共静态最终字符串PAYMENT_CHEQUE =check;
我曾经在哪里要求ie在jsp页面中以及Action类我将引用上面的字符串常量
我在审查资源包之后想到的是,属性文件,我的问题是
From past Year are so, we have developed an application, in which we have used the static String Constants to store the Constants.Likepublic static final String PAYMENT_CHEQUE = "cheque";Where Ever I Require i.e. in the jsp pages as well the Action class I will be refering to the Above String ConstantI am thinking after reviewing the Resource Bundle, properties Files, My Question is
- 是否有任何性能损失如果I
使用属性文件与
静态字符串常量相比? - 哪个更好静态字符串
常量和属性文件键
值对? - 这是个好主意我们在jsp中使用
静态字符串常量(用于标记)
?
请建议我
推荐答案
一般情况下,使用硬编码字符串是坏主意,因为这意味着每个更改都需要一个新的编译 - 部署周期,而使用属性文件意味着应用程序需要重新启动而不需要其他内容(尽管有些人会说它本身就是一个高h支付价格)。使用属性文件的另一个好处是能够通过将应用程序切换到另一个文件来切换语言 - 比在代码中使用多组常量标签更合理。
In general, using hard-coded strings is a bad idea, because it means every change needs a new compilation-deployment cycle, whereas using a properties file means the application needs to be restarted and nothing else (although some would say that in itself is a high price to pay). Another advantage of using a properties file is the ability to switch languages by switching the application to another file - much more reasonable than having multiple sets of constant labels in code.
你可以像现在一样使用最终的静态String字段,只在应用程序的初始化阶段为它们提供一个读取ma属性文件的值,而不是为每个常量返回文件(这将是代价高昂的!)。这样您就不必进行应用程序范围的更改,并且您仍然享受我上面提到的优势。
You can use the final static String fields the same way you do right now, only give them a value read fro ma properties file at the application's initialization stage, rather than going back to the file for every constant (which would be costly!). That way you don't have to make application-wide changes, and you still enjoy the advantages I mentioned above.
这篇关于字符串常量与Java Web应用程序中的资源包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!