Page 1 of 1

forward all request parameters to a java Servlet

Posted: Tue Sep 09, 2008 4:20 am
by eljapi
This is the situation:

Im writing this site in PHP, and, because of some circumstances completely out of my control, i need to write a php script that dynamically passes every request parameter it recieves and sends it to some java servlet.

The java site has some 40 different servlets that i need to acces.

So im writing an "ajax_forward.php" script that should receive a $_POST['ajax_servlet'] parameter that indicates which servlet the rest of the parameters should be passed on to.

A possible solution might be to have php pass all parameters over to a curl command, but im just wondering if theres a 100% php solution that i just have not been able to stumble upon.

I've googled like crazy but... i guess i just have not used the right combination of keywords.

any ideas?

Re: forward all request parameters to a java Servlet

Posted: Tue Sep 09, 2008 9:37 am
by andyhoneycutt
When you say 100% php solution, do you mean you don't want to use any external modules like cURL (as in things you'll possibly need to apt-get)?

The first solution to a problem like this that comes to my mind is using cURL.

-Andy

Re: forward all request parameters to a java Servlet

Posted: Tue Sep 09, 2008 1:17 pm
by eljapi
cURL sounds great.

I've done mi research and there's only one problem left. How can i dinamycally read all of the request's parameter names and values?

is there a function that returns an array with all of the parameter names?

so i could wirte something like :

for each paramenterNames as paramenter

$URL=$parameter."=".$_POST[$parameter]."&"


can anyone give me an example?

Re: forward all request parameters to a java Servlet

Posted: Wed Sep 17, 2008 9:29 am
by andyhoneycutt
eljapi wrote:cURL sounds great.

I've done mi research and there's only one problem left. How can i dinamycally read all of the request's parameter names and values?

is there a function that returns an array with all of the parameter names?

so i could wirte something like :

for each paramenterNames as paramenter

$URL=$parameter."=".$_POST[$parameter]."&"


can anyone give me an example?
You could do something like this:

Code: Select all

$URL = "";
foreach( $_POST as $key => $value )
{
  $URL .= "$key=$value&";
}
$URL = rtrim($URL,"&");
-Andy

Re: forward all request parameters to a java Servlet

Posted: Wed Sep 17, 2008 12:06 pm
by Jenk
Why not just proxy or redirect to the serverlet with apache?