Re: java.applet.Applet.getParameter()
Thanks Tomas.. Guess I missed that in the docs.
Thomas Fritsch wrote:
blaine@worldweb.com wrote:
I would like to test to see if a parameter exists in the html file
prior to calling getParameter(<key>), however I can not find any sort
of method to allow me to do this.
Is there a containsKey() method or something similar so that I could
write code like:
String[] keys = {"key1","key2"};
Hashtable ht = new Hashtable();
for(int i = 0; keys.length > i; i++){
if ( <KEY EXISTS IN HTML PARAMETER LIST> ){
ht.put(keys[i], getParameter(keys[i]);
}
}
I know that I could just "try" and "catch" the getParameter, but this
does not seem as clean as just doing a test for existence.
Any help would be appreciated.
The getParameter(String) method is specified to return null, if the
parameter does not exist. Therefore, in you for-loop you can just do:
String value = getParameter(keys[i]);
if (value == null){
ht.put(keys[i], value);
}
There is no need for try/catch.
--
Thomas