从"webcontent"访问i18n属性文件.或"WEB-INF \ local";文件夹 [英] Accessing i18n properties file from "webcontent" or "WEB-INF\local" folder
问题描述
我正在开发需要为i18n的JSP/Servlet页面.我在互联网上看到的示例代码使用的是JSTL的setlocal和setbundle标签.他们将.properties
文件添加到java源文件夹或WEB-INF\classes
文件夹中.
I am developing a JSP / Servlet pages which needs to be i18n. The example codes which I have seen on the internet are using JSTL's setlocal and setbundle tags. And they are adding the .properties
file in the java source folder or WEB-INF\classes
folder.
我正在为该项目使用Apache Tomcat 6.0.32和JSTL1.2 jar文件.
I am using Apache Tomcat 6.0.32 and JSTL1.2 jar files for the project.
我想知道是否可以在webcontent\i18n
或WEB-INF\local
文件夹中添加.properties
文件.并使用JSTL标签访问它?
I wanted to know can we added the .properties
file in say webcontent\i18n
or WEB-INF\local
folder. And access it using JSTL tags?
推荐答案
它必须放在类路径中.它们处于 ResourceBundle
会默认从类路径加载它们.因此,将其放在类路径之外是行不通的.您总是可以像/WEB-INF/classes/local/filename.properties
这样将它们放在一个(子)包中.然后,您只能使用基本名称local.filename
而不是filename
来访问它.
It has to go in the classpath. They're under the covers loaded by ResourceBundle
which loads them by default form the classpath. So, putting it outside the classpath won't work. You can always put them in a (sub)package like so /WEB-INF/classes/local/filename.properties
. You should then only access it with basename local.filename
instead of filename
.
这篇关于从"webcontent"访问i18n属性文件.或"WEB-INF \ local";文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!