0

I want to put all the values in the catalina.properties and want to use them in jsp instead of having another property file.
Can anyone tell me how to do that.

Right now I'm using system.getProperty("variable name","default value") but it is not working .

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
  • What are you using as you backend to load the jsp? Java? – Rahul Shardha Dec 18 '13 at 22:29
  • yes.. i am using java as my back end – user3117065 Dec 18 '13 at 22:30
  • Ok. So why don't you open the file in java, scan/parse it and pass the properties on to your jsp? – Rahul Shardha Dec 18 '13 at 22:30
  • can you give little bit more clarity – user3117065 Dec 18 '13 at 22:32
  • Are you using some framework? Spring (most probable choice)? – Rahul Shardha Dec 18 '13 at 22:33
  • no.. i am not using any framework – user3117065 Dec 18 '13 at 22:34
  • Ok, I'm not sure how passing variables to jsp works exactly but I get tell you the following (not 100% so somebody correct me if I'm wrong). You can't use that call because system.getProperty does not exist within the context of the jsp. It exists within the context of the function that's calling the jsp. So, you need to open the file in the calling function same as you would open any file, parse it until you get the required term, then pass that value to the jsp from the `calling function` – Rahul Shardha Dec 18 '13 at 22:37
  • 1
    `catalina.properties` is used to configure the container. It sounds like a bad idea to use it to store webapp config. Just my 2 cents. – David Levesque Dec 18 '13 at 23:05

1 Answers1

0

You might want to try this from a servlet:

InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("/catalina.properties");
Properties properties = new Properties();
properties.load(input);

The rest is just a question of classpath, if everything is correct your properties should be loaded in the properties object where you will be able to retrieve the data you are looking for. Then it's just a question of how you decide to pass it to your jsp.