Accessing i18n properties file from “webcontent” o

2019-09-03 10:08发布

问题:

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.

I am using Apache Tomcat 6.0.32 and JSTL1.2 jar files for the project.

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?

回答1:

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.

See also:

  • How to internationalize a Java web application?


标签: jsp jstl