java 可以同时使用JSP和PHP吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2025912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:59:33  来源:igfitidea点击:

Is it possible to use JSP and PHP at the same time?

javaphpjsp

提问by James

1 function is written in Java while the API of another function is written in PHP. So, is it possible to use JSP and PHP at the same time?

第一个函数是用 Java 编写的,而另一个函数的 API 是用 PHP 编写的。那么,是否可以同时使用JSP和PHP呢?

回答by Pascal MARTIN

I would say that you could call (from your Java code)a different process to execute the PHP script, and then use the output of that PHP script in your Java code -- but that's certainly not optimal, and will not allow you to call only one PHP function.

我会说你可以(从你的 Java 代码)调用一个不同的进程来执行 PHP 脚本,然后在你的 Java 代码中使用该 PHP 脚本的输出——但这肯定不是最佳的,并且不允许你调用只有一个 PHP 函数。

Using both Java and PHP code in the same application seems a bit complicated, and I've never seen this done -- nor used in any way ; so, I would probably rewrite the PHP code to Java (or the Java code to PHP), so the whole application is written in only one of those two languages.

在同一个应用程序中同时使用 Java 和 PHP 代码似乎有点复杂,而且我从未见过这样做过——也没有以任何方式使用过;因此,我可能会将 PHP 代码重写为 Java (或将 Java 代码重写为 PHP),因此整个应用程序仅使用这两种语言中的一种编写。


I've never tried it, but maybea possibility would be using Quercus-- see, for instance : java and php integration


我从来没有尝试过,但也许使用Quercus是一种可能性——参见,例如:java 和 php 集成

It seems to be able to run Drupal (a popular PHP CMS ; which means quite a lot of functionnalities): Running Drupal 6.2 on Resin 3.1.6; so I'd say it might be worth a look...

它似乎能够运行 Drupal (一种流行的 PHP CMS;这意味着相当多的功能)在 Resin 3.1.6 上运行 Drupal 6.2;所以我会说它可能值得一看......

回答by Don

When you say JSP and PHP, it is a mixed bag. Java and PHP as two languages, OK. But JSP and mod_PHP as two server interfaces, NO.

当您说 JSP 和 PHP 时,它是鱼龙混杂。Java和PHP作为两种语言,OK。但是JSP和mod_PHP作为两个服务器接口,NO。

To run a mod_PHP program you must setup certain (many) server variables which PHP will use. The same to run a Jsp program, the server environment must be established.

要运行 mod_PHP 程序,您必须设置 PHP 将使用的某些(许多)服务器变量。同样要运行一个Jsp程序,必须建立服务器环境。

But to run a mod_PHP program and call (in some fashion) a Java program, as @Pascal wrote, sure, but the linkage is inefficient. And the same the other way, a JSP program can launch a PHP (CLI) program too.

但是要运行一个 mod_PHP 程序并(以某种方式)调用一个 Java 程序,正如@Pascal 所写的那样,当然,但链接效率低下。反过来,JSP 程序也可以启动 PHP (CLI) 程序。

回答by Thorbj?rn Ravn Andersen

In general no. There is, however, a PHP implementation written in Java which will most likely allow you to do what you need which can run in most web containers.

一般来说没有。但是,有一个用 Java 编写的 PHP 实现,它很可能允许您执行可以在大多数 Web 容器中运行的所需操作。

Have a look at Quercus from Caucho. Here is the tutorial: http://quercus.caucho.com/quercus-3.1/examples/quercus.xtp

看看来自 Caucho 的 Quercus。这是教程:http: //quercus.caucho.com/quercus-3.1/examples/quercus.xtp

回答by Ignacio Vazquez-Abrams

There is Java integrationavailable in PHP, but that's for accessing Java classes in PHP and probably won't let you use JSP without a lot of hacking.

Java集成在PHP可用的,但是这是用于访问PHP的Java类,可能不会让你使用JSP没有很多的黑客。

回答by Chandra Patni

You can do it if you are App servers like Resinwhich support PHP or using experimental PHP / Java Integration. Note that running PHP on Resin may not support all extensions for a given application but I have ran Wordpress on Resin and it's neat.

如果您是像Resin这样支持 PHP 或使用实验性PHP/Java 集成的应用服务器,则可以这样做。请注意,在 Resin 上运行 PHP 可能不支持给定应用程序的所有扩展,但我已经在 Resin 上运行了 Wordpress,它很简洁。

回答by Blessed Geek

You should consider the following design.

您应该考虑以下设计。

  1. Your PHP pages run on Apache http with the mod.
  2. Your JSP pages run on Apache tomcat.
  3. Run a memory based rdbms.
  1. 您的 PHP 页面使用 mod 在 Apache http 上运行。
  2. 您的 JSP 页面在 Apache tomcat 上运行。
  3. 运行基于内存的 rdbms。

All three is run on the same system.

这三个都运行在同一个系统上。

Inter PHP-JSP communication would be conducted on two ends:

PHP-JSP 之间的通信会在两端进行:

  1. the frontend JSP and PHP web services
  2. and the backend memory-based rdbms.
  1. 前端 JSP 和 PHP Web 服务
  2. 和后端基于内存的 rdbms。

Disclaimer: I have never even seen any PHP code in all my 30 years' programming life. Perhaps, once, actually. Therefore, I have faint idea how difficult it might be to have PHP serve web services.

免责声明:在我 30 年的编程生涯中,我从未见过任何 PHP 代码。也许,曾经,实际上。因此,我不知道让 PHP 提供 Web 服务有多困难。