I'm interested in this also. I have these test scripts working (ok, over simplified) but they might help.
in a script I call test client:
<?php
$handle = fopen("http://www.mysite.com/test/testhost.php?code=2", 'r');
$remoteTxt = fgets($handle, 4096);
fclose($handle);
echo $remoteTxt;
?>
in a script I call testhost
<?php
if ($code == 1) echo 'hello world';
else echo 'hello planet';
?>
I'm working on the basis that the returned code must be echo'd or printed. Therefore if in the jsp you do what would normally send code to the browser you will catch it in your variable.
I'm mucking around with it right now to see if I get referrer details sent through normally. You can test it at
http://property.digitalrice.com/test/testclient.php