forward all request parameters to a java Servlet

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eljapi
Forum Newbie
Posts: 2
Joined: Tue Sep 09, 2008 4:10 am

forward all request parameters to a java Servlet

Post 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?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: forward all request parameters to a java Servlet

Post 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
eljapi
Forum Newbie
Posts: 2
Joined: Tue Sep 09, 2008 4:10 am

Re: forward all request parameters to a java Servlet

Post 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?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: forward all request parameters to a java Servlet

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: forward all request parameters to a java Servlet

Post by Jenk »

Why not just proxy or redirect to the serverlet with apache?
Post Reply