GWT 客户端应用程序托管/部署
我想在我的新项目中使用 gwt + php、html,并且想知道如何编译/部署 gwt 创建的 html + jscript/ajax 文件到非 jvm 服务器(如 apache 服务器)上。
1)我想使用 gwt 作为我的客户端接口,现在当我这样做时,我想对服务器进行异步调用并让 php 提供数据库中的数据。 2)为此,我想知道gwt项目是如何在eclipse中编译的,那么war目录中的所有文件都放在apache服务器等上?有这方面的指南吗?
我在网上找到的只是有关使用 gwt 支持 jvm 的 Web 服务器的示例和教程,即使您不想在服务器端使用 java 技术。
谢谢
i want to use gwt + php, html for my new project and would like to know how i can compile/deploy the html + jscript/ajax files that gwt creates onto a non jvm server like an apache server.
1) i want to use gwt for my client side interface, now when i do that i want to make asynchronous call to the server and have php serving the data from database.
2) for that i want to know how the gwt project is compiled in eclipse then what all files from the war directory are put on the apache server etc? is there any guide for this?
all i found on the web is exaample and tutorials on using a jvm supported web server for gwt even if you dont want to use java technology on the server side.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所了解的,war 文件夹是 Java servlet 容器完成其工作所需的所有内容。这包括 GWT 中的静态编译文件、添加到文件夹中的任何图像或 html,以及 servlet 容器将运行的代码。
如果您使用 PHP 服务器,您可能只需要编译后的 JS/HTML/图像 - 这些都位于具有 GWT 模块名称的文件夹中。编译应用程序,然后将该目录复制到由 apache 提供的文档文件夹中。要运行该模块,请在 html 页面中加载
.nocache.js
文件(该文件可以是静态的,也可以由 php 文件写出)。如果您正在 Eclipse 中使用 Google Plugin for Eclipse 创建的项目,则可以复制 war 文件夹的内容,减去 WEB-INF(其中包含 Java 特定的内容),然后使用它。然后您将拥有一个可工作的 html 文件和已编译的 javascript。
要调用您自己的服务器,请使用
RequestBuilder
类 - 它包含了浏览器的基本 AJAX 功能,并提供了一种简单、一致的方法来创建和配置请求以及获取回调当它完成时。要处理数据,这将取决于您的 PHP 代码发送回客户端的数据类型 - GWT 包括读取 xml 和 json 的选项,并且由于 RequestBuilder 将为您提供发送回的原始字符串,因此您也可以这样做你自己的解析。
最后,请记住,复制编译后的模块后,您可以使用 PHP 运行 apache 服务器,但可以使用 Java 调试 GWT 代码。如果 apache 在端口 80 上运行,则只需启动开发模式(您可能希望停止 GWT 开发模式启动服务器,取消选中 GWT 运行配置中的“运行内置服务器”复选框)并加载页面,使用参数 gwt.codesvr=localhost:8080。在您的网址栏中,这可能看起来像这样:
The war folder, as you've figured out, is all of the things a Java servlet container will need to do its job. This includes the static compiled files from GWT, any images or html added to the folder, and the code that the servlet container will run.
If you are working off of a PHP server, you probably just want the compiled JS/HTML/images - these are all in a folder with the name of your GWT module. Compile the app, and copy that directory into your documents folder that is served by apache. To run the module, load the
.nocache.js
file in your html page (which may be static, or may be written out by a php file).If you are working from a project in Eclipse, created by the Google Plugin for Eclipse, you can copy the contents of the war folder, minus the WEB-INF (which holds the Java specific stuff), and just use that. You'll then have a working html file and compiled javascript.
To make calls to your own server, use the
RequestBuilder
class - this wraps up the basic AJAX features of the browser, and gives a simple, consistent way to create and configure the request, and to get a callback when it has finished.To deal with data, it will depend on what kind of data your PHP code is sending back to the client - GWT includes options for reading both xml and json, and since the RequestBuilder will give you the raw string sent back, you can also do your own parsing.
Lastly, remember that after you copy over the compiled module, you can run your apache server with PHP, but debug the GWT code in Java. If apache is running on port 80, the simply launch dev mode (you may wish to stop GWT dev mode from starting a server, untick the 'run built-in server' checkbox in the GWT run configuration) and load the page, with the argument gwt.codesvr=localhost:8080. This may look something like this in your url bar: