ResourceBundle object is used for locale in java and internationalization. ResourceBundle is basically used for local language like Spanish, French, and English. According to the computer regional area setting, it configure to that language.
We are explaining how to use ResourceBundle’s properties file and get key value from properties file.
These properties file can use for different purpose here. We are not only using properties file for locale, also using for making database connection.
Copy properties file in WEB-INF/classes folder
Suppose we have file commonVariable.properties in WEB-INF/classes folder
# forum path and properties forum.path=forum forum.url=forum forum.database=jspforum forum.use=yes
JSP which is getting values from ResourceBundle properties file
resource.jsp
<%@ page language="java" import="java.util.*" %> <% ResourceBundle resource = ResourceBundle.getBundle("commonVariable"); /// commonVariable.properties file will be in WEB-INF/classess folder String sPath=resource.getString("forum.path"); String sName=resource.getString("forum.database"); System.out.println(sPath); System.out.println(sName); %>



Link to Us