开发者

php code to jsp code

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!


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


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜