1

I'm "translating" a PHP class in Java.

I've a function that takes a key and checks if it's in the $_POST array.

How could I do a similar thing from a class Java method?

Sefran2
  • 3,578
  • 13
  • 71
  • 106

2 Answers2

1

Java doesn't support associative arrays. If you're using a HashMap:

HashMap hMap = new HashMap();
//(...)
ht.put("key","One");
ht.containsKey("key"); // returns true

If you're using a hashtable:

Hashtable ht = new Hashtable();
//(...)
ht.containsKey("key");

Unless you mean how to access POST parameters, then check this question and this documentation

Community
  • 1
  • 1
MMM
  • 7,221
  • 2
  • 24
  • 42
  • Thank you. I mean how to access POST parameters. But if I've not a servlet? I'm trying to translate in java the botsko.net/blog/2009/04/07/jquery-form-builder-plugin example from php. – Sefran2 Mar 20 '12 at 10:51
  • If it's not a servlet then what is it? How does it act as a server? – MMM Mar 20 '12 at 10:55
  • I'm trying to use a jquery formbuilder plugin following the php example on botsko.net/blog/2009/04/07/jquery-form-builder-plugin. My idea was to "translate" the classes in java and then create the corresponding objects and call the methods from a jsp in <% %> (without using a servlet). But now I'm realizing that it's impossible a complete "translation" from php to java. – Sefran2 Mar 20 '12 at 13:26
  • Hi @Cricket, I'm stuck with the same plugin. I'm trying to translate it from PHP to Java, but since I don't know PHP much, I'm stuck. Did you complete this project? What did you use eventually? Can you kindly guide me? – LittleLebowski Aug 02 '13 at 14:51
  • @LittleLebowski: The project on github uses object oriented php. You could use the same two classes by making changes according to your project. As java doesn't support associative arrays like PHP, I've used `Hashtable`, but it complicates some things that in php are simpler. However, you should try to understand the php code and above all the json structure. – Sefran2 Aug 03 '13 at 16:43
0

Look up request.getParameter()

http://www.roseindia.net/jsp/GetParameterMethodOfRequest.shtml

Ynhockey
  • 3,845
  • 5
  • 33
  • 51