Ropardo Sowftware development company

Experience software development with ROPARDO S.R.L.

RSS Feed
RSS Feed
  • Home
  • About ROPARDO S.R.L
  • Our websites

Two options for showing properties from a .properties file

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.

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Get Shareaholic
Tags: JSP properties file

 Posted in: Java
July 15, 2010 | Gabriela Radu | 3 Comments

3 Responses

  • coffeegift
    August 2, 2010
    1

    Give you free coffee gifts

  • coffee gifts
    August 25, 2010
    2

    excellent writing .

  • Robert Wilson
    October 18, 2010
    3

    thanks for the post

Leave a Reply

 


  • « Previous post
  • Next post »
  • Recent Posts

    • Installing PyGraphviz on Windows
    • Convert python object to XML representation
    • Liferay Portlet Development
    • Norway Road Show 2011 private meeting invitation
    • Oracle OpenWorld 2011
  • Ropardo is Hiring

  • Subscribe

    • Add to Google Reader or Homepage Add to netvibes TopOfBlogs
  • Recent Comments

    • Rajkumar Pomaji on Bluetooth PC Remote Control
    • Stelian Morariu on GWT 2.1 – Uploading a file using the RPC mechanism
    • Sergio on GWT 2.1 – Uploading a file using the RPC mechanism
    • Artem on Liferay: Deployment will start in a few seconds… and how to realy start
    • rkd80 on GWT 2.1 – Uploading a file using the RPC mechanism
  • Archives

    • November 2011 (1)
    • September 2011 (4)
    • July 2011 (3)
    • June 2011 (2)
    • May 2011 (4)
    • April 2011 (4)
    • March 2011 (3)
    • February 2011 (2)
    • January 2011 (2)
    • December 2010 (1)
    • November 2010 (4)
    • October 2010 (4)
    • August 2010 (3)
    • July 2010 (3)
    • June 2010 (6)
    • May 2010 (8)
    • April 2010 (7)
    • March 2010 (9)
    • February 2010 (6)
    • January 2010 (5)
    • December 2009 (7)
    • November 2009 (9)
    • October 2009 (10)
    • September 2009 (14)
    • August 2009 (10)
    • July 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (1)
    • March 2009 (1)
    • October 2008 (3)
    • October 2007 (3)
    • July 2007 (4)
    • June 2007 (1)
    • May 2007 (3)
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Categories

    • News (15)
    • Ropardo Team (8)
    • Ropardo Products (6)
      • File Tracking Client (4)
      • iManagement (2)
    • Software Development (83)
      • Microsoft.NET (22)
      • Java (40)
      • Oracle (8)
      • Power Builder (3)
      • Liferay (5)
      • Lotus Notes (9)
      • xWiki (4)
    • System Adminstration (13)
      • Linux (10)
      • Windows (3)
    • Programming (1)
    • Uncategorized (3)
    • Databases (10)
      • MSSQL (5)
      • PostgreeSQL (3)
    • Microsoft.NET (1)
    • Web Development (28)
      • ASP/ASPX (3)
      • Content Management Systems (1)
      • HTML/CSS (5)
      • Javascrip/AJAX (8)
      • PHP (7)
    • Oracle E Business Suite (6)
  • Tags

    .NET ajax blog C# certification client CMS control css database Debugging django Domino Eclipse extension file tracking filter fun gentoo google Hibernate how to html image iManagement import Java javascript jQuery liferay Linux Lotus Notes lotus script Oracle Oracle BI Publisher 11g PHP portal PostgreSQL powerbuilder Python SQL Telerik velocity xml Xwiki

© 2010 ROPARDO s.r.l..

Powered by WordPress. Styled by Ropardo