tags:

views:

39

answers:

2

I'm a PHP coder but need to code some JSP...

I need help... What is the equivalent of this PHP code?

foreach($_POST as $key => $value){
   $$key = $value;
}

to jsp code...


further notes: the above codes is just a short cut of something like this,

$name = $_POST['name'];
$age = $_POST['age'];
$gender = $_POST['gender'];

and this sample 3 lines of codes in JSP is,

String name = request.getParameter("name");

Thanks!

+2  A: 

http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/c/forEach.html

for the variable variable name thing - i dont think that is possible in JSP (you do know that JSP is just a better template engine?)

also ... you do know there is google right? :P

Tobias
yeah.. I know google... he's my friend... but he's not of help much right now... that's why I'm asking SO, my other friend... and I'm really way new to JSP.... sorry for the noob question...
Reigel
last time i saw JSP was in 2001... and all i did is to create some html templates - means im not a big help but i think if you look at example code it cant be that hard to figure out a foreach. but im still kinda sure that the variable variables names is something jsp will not do. but im happy to be proven wrong :)
Tobias
That's my thought too... well, it's going to be the two of us who will be happy if one will prove it... that JSP can do that too. ;)
Reigel
+2  A: 

This is untested and I'm quite new at JSP/Servlets, but it seems the Request object has a "getParameterNames" function that will return you the names of all parameters in the request.

If you enumerate through those you should be able to access the values with "getParameter".

http://java.sun.com/javaee/6/docs/api/javax/servlet/ServletRequest.html#getParameterNames()

jlindenbaum