开发者

How to redirect to another jsp page in php

开发者 https://www.devze.com 2023-01-20 00:01 出处:网络
I have 1 php page that is doing some manipulation and store data in 2 variable, now I want to pass this data toanot开发者_C百科her page and that page is in jsp. I dont want to click anywhere, mean my

I have 1 php page that is doing some manipulation and store data in 2 variable, now I want to pass this data to anot开发者_C百科her 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


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).


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


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)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消