Two options for showing properties from a .properties file

Share

Task: Show in a jsp file some properties you have declared in a .properties file in the project
Solution1:
Use the Jquery Plugin for internationalization. Think of this as using the ResourseBundle of Java. Loading and parsing the information from the .properties files and showing them in the jsp page.
This is the official documentation of this plugin:  jquery
To simplify this, here is what you need to:
– structure your resources:  create a “scripts” (just an example of naming) folder in your WebContent folder. Here add the Jquery script(get the latest from here. ), the internationalization plugin(from here )

– and create another js file of your own in which you state that on page loading you want to invoke the plugin:

jQuery.i18n.properties( {
name : 'messages',
path : 'i18n/',
mode : 'map',
});

These code snippets can be found in the official documentation as well.
– create another folder, my choice of names was: i18n and here add your properties file: “messages.properties”. In this file you will add your properties, for instace:

ro.client.welcome_text = "Welcome message..."

– next, in your jsp file import the /js files we talked about above.
Now, in the jsp file, add id’s to the div’s or other html tags to where you want to print the properties from the .properties file. Example:

 <b><label id = "welcome_text"></label>

Now, in the head tag of the page, in a javascript tag, on document ready get the above id and replace it with your wanted property:

$j('[id=welcome_text]').text(jQuery.i18n.prop('ro.client.welcome_text'));

And this is it. Pretty straight forward right?

Solution 2:
Same task, different approach.
Nothing of the above, nothing to import, in the body add this block:

&lt;%@page import="java.io.*,java.util.*" %&gt;
&lt;% Properties prop=new Properties();
InputStream stream =  application.getResourceAsStream("the path to your properties file");
prop.load(stream); %>

And when you want to show the properties:

<strong><% out.println(pro.getProperty("welcome_text")); %></strong>

And this is about it too.

Furthermore, I found this interesting, well written article about best practices regarding JSP( here ). Remember this “Note that you should not place sensitive data in JSP source code, not even inside JSP comments” and be with care when adding logic in your jsp page.

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

3 thoughts on “Two options for showing properties from a .properties file”
  • coffeegift says:

    Give you free coffee gifts

    August 2, 2010 at 7:02 pm
  • coffee gifts says:

    excellent writing .

    August 25, 2010 at 4:10 am
  • Robert Wilson says:

    thanks for the post

    October 18, 2010 at 9:17 am

Comments are closed.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close