Jump to content

php calling jsp page


digbyn

Recommended Posts

Hi All,

Hoping you can help, have spent many hours searching around and not finding much. I have a main php program running and I wish to make a call to execute a JSP page, sounds simple enough. I have tried include but did not work, header location but this causes header redirect problems and curl which does not work? Also tried file_get_contents, did not work either? I wish to stay in my main.php program and not get redirected, just make a call and successfully execute the JSP page running on another server? Hope this is clear, any help much appreciated.

this works...



PHP Code: [select]

<?php
$homepage 
file_get_contents('http://www.example.com/');
echo 
$homepage;
?>

but this does not work



PHP Code: [select]

<?php
$homepage 
file_get_contents('http://hostname:8080/pagename.jsp?param1=value1&param2=value2/');
echo 
$homepage;
?>

 

have also tried CURL, also times out.



PHP Code: [select]

$URL ='http://hostname:8080/pagename.jsp?param1=value1&param2=value2'
//Initialize the Curl session
$ch curl_init();
//Set curl to return the data instead of printing it to the browser.
curl_setopt($chCURLOPT_RETURNTRANSFER1);
//Set the URL
curl_setopt($chCURLOPT_URL$URL);
//Execute the fetch
$data curl_exec($ch) or die(curl_error($ch));
//Close the connection
curl_close($ch);
print 
$data;

 

Link to comment
Share on other sites

Both the file_get_contents() and cURL versions should work. If they're timing out then there's a problem accessing that URL. For example, are you sure you have the right hostname? And that it really is on port 8080?

 

By the way, if you're just outputting it then a header() redirect may be appropriate (I don't know what "header redirect problems" are) or, if it has to be code, readfile.

Link to comment
Share on other sites

Hi Requinix,

 

Thanks for the reply, much appreciated, its been years since I last did this!

 

Yes I thought file_get_contents and cURL would work but no, so I assume there is something else going on and will investigate. Yes I have a java app deployed on 8080.
I do have it working with header redirect as follows.

 

...
...
ob_end_clean();
header('Location: http://example.com:8080/page.jsp');
exit();

Problem is, thats where the show stops...on that jsp page, I would like to just 'execute' the jsp page and then return to the master main.php program and keep running not redirect permanently to that jsp page.  I have program1.php calls program2.php that executes the header redirect but does not return back to program1.php.

 

Sorry, hope this is making sense? Thanks for the help. Digby.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.