连接 C++ JavaScript 后端

发布于 2024-09-01 00:24:53 字数 160 浏览 2 评论 0原文

我希望制作一个网站,显示谷歌地图,其中包含基于 C++ 函数返回的信息的点。我知道您可以使用 Java Server Pages 通过 javascript 调用服务器上的 java 方法。有没有办法将服务器上的 C++ 代码与 javascript 连接起来,以便产生与 java 服务器页面相同的结果?

I was hoping to make a website that displays a google map with points based of information returned by a C++ function. I know you can use Java Server Pages to call java methods on the server with javascript. Would there be a way to connect C++ code on the server with javascript in order to produce the same result as java server pages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-09-08 00:24:55

由于 JavaScript 在完全不同的环境中运行,该环境通过 HTTP 连接与 Web 服务器分开,因此最好的选择是在附加了特定 C++ 代码的特定 URL 上向服务器端发出 HTTP 请求。

您可以使用核心 XMLHttpRequest 在 JavaScript 中触发异步 HTTP 请求“Ajax” 背后的技术。 w3schools 提供了 Ajax 的简明简介。为了使其不那么冗长和臃肿,您可以考虑使用 jQuery 库,每个库下面都有一个 $.ajax 函数用于此目的。


也就是说,Java Server Pages 绝对不能与 JavaScript。 JSP 是一种基于 Java 的服务器端视图技术,它提供了一个用于编写 HTML/CSS/JS 的模板,并提供了动态控制页面流以及使用标签库和表达式语言与后端 Java 代码交互的功能。它全部在服务器计算机上运行,​​生成 HTML 页面并通过 HTTP 将其发送到客户端。 JSP 的 C++/C#/NET 对应部分是 ASP

Since JavaScript runs at a completely different environment which is separated from the webserver by a HTTP connection, your best bet is to fire a HTTP request to the server side on a specific URL which has the particular C++ code attached.

You can fire asynchronous HTTP requests in JavaScript using XMLHttpRequest, the core technique behind "Ajax". The w3schools provides a concise introduction to Ajax. To make it all less verbose and bloated, you may consider to grab the jQuery library which has under each an $.ajax function for this purpose.


That said, Java Server Pages is absolutely not to be compared with JavaScript. JSP is a Java based server side view technology which provides a template to write HTML/CSS/JS in and offers capabilities to control the page flow dynamically and interact with backend Java code using taglibs and expression language. It runs all on the server machine, produces a HTML page and sends it over HTTP to the client side. The C++/C#/NET counterpart of JSP is ASP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文