-1

Most sites I have found are doing the properties in only Java, not using JSP. This says its a beginners guide but it doesn't make much sence to me: Site Link

  • I can't follow where or how the file is being made, how it is named, and where it is stored. Can you explain this?

  • Do I need to make a Java class to make this work, or can everything just be done in JSP with an import or two?

  • Then once it is created, do you have to make defaults for all key's that you plan to use or can you make new keys as you need to add them? (and how?)

  • When you have those saved, what is the simplest way to pull the value of the key out of the file to use on my webpage? (plan to pull that key and use if/else statements to do stuff based on it).

Sorry this is so many questions. I really have no clue where to even start with this and nothing i've searched so far has helped me get started. Please don't say just look at a tutorial because I have looked at quite a few and nothing so far has helped. Also, please explain in as simple terms as possible and with examples if possible as well. I can understand things better when I'm given an example and its explained to me how to follow it.

Thanks

Flame
  • 1
  • 1
  • This question is answered in http://stackoverflow.com/questions/1140653/how-to-load-a-properties-file-into-a-jsp – carpamon Jan 13 '12 at 20:47
  • If it is, i'm still not seeing it. That doesn't help me. – Flame Jan 13 '12 at 20:56
  • Why would you *want* to do this in a JSP? That aside, any Java code *can* be put inside a JSP. The linked question describes how to retrieve the values. I don't see any reason to *create* the file in a JSP when you could just edit it and deploy it. – Dave Newton Jan 13 '12 at 20:59
  • It explains where you should create the .properties file and how you can access the properties. – carpamon Jan 13 '12 at 20:59
  • As commented on your previous question, read Oracle's own tutorial. More official/authoritative can't you get. Enter "properties tutorial site:oracle.com" in Google and click the [1st link](http://docs.oracle.com/javase/tutorial/essential/environment/properties.html). There's a chapter "Saving properties" complete with a concrete example. You only need to change the location of the file to be an absolute path. – BalusC Jan 13 '12 at 21:13

1 Answers1

1

Look at this description.

While a properties file doesn't need to end in ".properties" it is basically a key->value pairing where

key1=value1
key2=value2
key3=value3

(and so on). There's a java.util.Properties class which can read this file easily (the Properties class) and can write the values easily. The result is a Map where the keys are the "keys" of the properties file, and the stored items are the "values" of the same file.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • I am just wondering why use Properties, when we can use a HashMap? Is it because, we can't load properties from a Property file into HashMap directly? –  Jan 13 '12 at 21:10
  • 2
    Properties are more like Hashmaps with default behaviors useful for saving and loading the values to disk. With a pure Hashmap, you don't get any file handling "extras", you'd have to write that part yourself. Also, the APIs are not exactly aligned (due to historical reasons). – Edwin Buck Jan 13 '12 at 21:14