1

I have 1 php page that is doing some manipulation and store data in 2 variable, now I want to pass this data to another page and that page is in jsp. I dont want to click anywhere, mean my php will call automatically to jsp page in last.

Please tell me how can i do this.

Thanks, Manoj Singhal

Manoj Singhal
  • 19
  • 1
  • 2

5 Answers5

3

Try this

<?php
  $var1 = 'some_value';
  $var2 = 'some_other_value';
  header('Location: jsppage.jsp?var1='.$var1.'&var2='.$var2);
  exit;
?>

You values will be available in jsp script trough request.getParameter("var1") and request.getParameter("var2") (might be wrong, have very little knowledge on jsp).

egis
  • 1,404
  • 2
  • 11
  • 24
  • Always, always URL_ENCODE your variables when you want to pass them via URL, or you're going to hit trouble as soon as a single character is not valid to be used in the URL. Remember, the internet is mostly Unicode (UTF-8) nowadays, but URLs only support a small range of the charset as valid URL characters! Check the specs: http://www.w3.org/Addressing/URL/url-spec.txt or - at least - check the easier to read wikipedia article: http://en.wikipedia.org/wiki/Percent-encoding to learn why you should url_encode your data. –  Dec 16 '11 at 05:38
2

Either store the data in a file or a database and do a:

header('Location: thejsp.jsp'); 
die();

and then let the jsp retreive the data from that file or database.

You also could do some curl requests passing the data via GET or POST

DarkCygnus
  • 7,420
  • 4
  • 36
  • 59
ITroubs
  • 11,094
  • 4
  • 27
  • 25
  • Not in a file! That might produce racing conditions (as local storage takes time and multiple requests are to be expected), which could break the stored data. If, the database would be a solution. Even when I think that it is overkill just to pass on two variables to a jsp file, as that can be done via the URL too. Also, OP would need to solve the problem to know which client receives which stored data. After all, if the data were always the same, it could have gotten hardcoded into the jsp... so variable data is to be expected. So, which client gets what data from the database? Good luck! –  Dec 16 '11 at 05:31
1

Assuming that you want to reuse the same request parameters on the JSP:

If it's a GET request, do:

header('HTTP/1.1 302 Moved Temporarily');
header('Location: http://example.com/page.jsp?' . $_SERVER['QUERY_STRING']);
exit();

If it's a POST request, do:

header('HTTP/1.1 307 Temporary Redirect');
header('Location: http://example.com/page.jsp');
exit();

(with a 307 the client will reapply the POST request including parameters on the target page)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

You can use CURL to fetch data from the JSP page and then show it to your PHP client. In this scenario, your client (browser) will connect to your JSP application server internally and you can pass data through a URL. After that, you use your JSP output as PHP output.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
0

That's easy:

  <?php
  /* 
     Prevent errors or output from spoiling the headers we're using later on.
     Every output before the headers are posted will break the headers and fail. 
  */
  ob_start();
  ...your code...
  $var1 = 'some_value';
  $var2 = 'some_other_value';
  ...your code...
  ob_end_clean();

  /* 
     Make sure you url-encode your variables so they don't break!
  */
  $location  = 'http://www.yourdomain.com/yourtargetpage.jsp?';
  $location .= 'var1='.url_encode($var1);
  $location .= '&amp;';
  $location .= 'var2='.url_encode($var2);

  /*
     Redirect to $location, 
     Using a 301 redirect (not 302!), 
     With TRUE to replace default HTTP code with 301 code and redirect.
  */
  header('Location: '.$location, 301, TRUE);
  exit();
  ?>

Now, all you have to do is to *url_decode* the variables in your jsp page and you're set.