Sample Application: Resource File
This example demonstrates the usage of "resource.properties" files in JSP. that is, how to store string constants or error messages in a resource.properties file and how to display it in the JSP page.
This page demonstrates the usage of "properties" files in JSP. Initially the content of the file should be made to InputStream of bytes. This stream is loaded to Properties as keys and its corresponding values. Values can be retrieved by passing the corresponding key.
You can download the source of this Sample Application here.
This is illustrated based on the assumption that you are you're already familiar with JSP, Servlet technologies. and equipped with a Servlet-capable Web server.
Apache Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. You can download the latest version of Apache Tomcat from here
/webapps/
/webapps/constants/
/webapps/constants/web/
/webapps/constants/web/index.jsp
/webapps/constants/web/ApplicationResource.properties
/webapps/constants/web/META-INF/context.xml
/webapps/constants/web/WEB-INF/web.xml
/webapps/constants/src/
/webapps/constants/src/java/
Lets go over each one:
/webapps/
The /webapps/ directory is our web server document root.
/webapps/constants/
/constants/ is the subdirectory where our application is accessed by the browser.
/webapps/constants/web
/web/ is the subdirectory where our JSP files and xml files have been kept.
/webapps/constants/web/index.jsp
index.jsp will be the entry point of our application. The web browser will be accessing this via http://yourdomain.com/constants. This page demonstrates the usage of "properties" files in JSP. Initially the content of the file should be made to InputStream of bytes. This stream is loaded to Properties as keys and its corresponding values. Values can be retrieved by passing the corresponding key.
/webapps/constants/web/ApplicationResource.properties
ApplicationResource.properties can be used to define all the error message for your input validations like, errors.length.fieldname=<font color="red">{0} - user name must be less than 25 characters </font>
/webapps/constants/web/META-INF/context.xml
context.xml will specify the context path to our project. In our case context path is "/constants"
/webapps/constants/web/WEB-INF/web.xml
web.xml acts as the deployment descriptor for our application. It is held in the application's WEB-INF directory. It defines a number of parameters that are used when the web application is deployed into the Tomcat Servlet/JSP container.
/webapps/constants/src/
This folder holds all the source of our web application.
/webapps/constants/src/java/
java This folder holds all the java files necessary for our application. Servlets are also stored in this directory. You can also store the files in a package structure.