服务器端 JavaScript 是如何使用/实现的?

发布于 2024-08-08 14:02:28 字数 302 浏览 5 评论 0原文

我很早就知道服务器端 JavaScript,但我不知道它是如何工作的。有人能指出我正确的方向吗?

我对如何使用服务器端 javascript + Java Servlet 技术感兴趣

编辑

太棒了!我以前见过这些技术,但由于某种原因,我没有将它们与“服务器端”javascript 联系起来(doh!)

补充问题:如果我想使用 javascript 库来创建内容(例如 ExtJs),我可以吗?能够像在客户端一样在服务器端修改“文档”吗?

(我想我会在第一次尝试中找到答案)

I'm aware of server-side javascript for a long time now, but I don't have a clue about how it works. Could someone point me in the right direction?

I'm interested in how to use server-side javascript + Java Servlet technology

EDIT

Great! I have seen those technologies before, but for some reason I didn't associate them with "server-side" javascript ( doh! )

Complementary question: if I want to use a javascript library to create content ( ExtJs for instance ), am I able to have a "document" to modify in the server-side as I do in the client?

( I guess I'll find out in my first attempts )

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

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

发布评论

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

评论(7

请叫√我孤独 2024-08-15 14:02:28

运行 javascript 服务器端需要一个可以嵌入的 javascript 引擎。大多数这些“嵌入式”引擎都提供 API,让您可以在执行的 javascript 代码和您自己的对象/方法之间进行交互。例如,您可能连接了 javascript 代码以允许执行用 Java 或 C# 编写的函数,或者您可能会扩充脚本的符号表以包括对系统中非 javascript 对象的访问。

我会看一下其中一些引擎,我猜 Rhino 可能最适合您,因为它是用 Java 编写的。他们的教程概述了将 Rhino 嵌入到 Java 环境中。

  1. Rhino 嵌入教程:http://www.mozilla.org/rhino/tutorial.html
  2. V8是Google的引擎。 V8 目前不是线程安全的,因此它可能不适合您在服务器环境中的需求。 http://code.google.com/p/v8/
  3. SpiderMonkey 是驱动引擎Firefox 的 JavaScript 执行。直接是 C。 http://www.mozilla.org/js/spidermonkey/

< strong>编辑以回答您的第二个问题。

我不确定你所说的由 javascript 库生成的内容到底是什么意思。然而你提到了 ExtJS,我相信这意味着 HTML 内容?了解 DOM(Javascript 可以读取和修改但不是 Javascript 本身的“一部分”)和 Javascript 语言之间的区别非常重要。如果您需要 DOM 服务器端的想法,那就另当别论了,如果您需要 Javascript 语言,那么上述选项应该可以帮助您。

Running javascript server side requires a javascript engine that can be embedded. Most of these "embeddable" engines provide an API that lets you interface between the executing javascript code and your own objects/methods. For example, you might have javascript code hooked up to allow the execution of functions written in Java or C#, or you might augment the symbol table of a script to include access to non-javascript objects in your system.

I would take a look at some of these engines, I'm guessing Rhino may be the best fit for you as its written in Java. Their tutorials outline embedding Rhino in a Java environment.

  1. A Rhino embedding tutorial: http://www.mozilla.org/rhino/tutorial.html
  2. V8 is Google's engine. V8 is not currently threadsafe, so it probably won't suit your needs in a server environment. http://code.google.com/p/v8/
  3. SpiderMonkey is the engine powering Firefox's javascript execution. It's straight C. http://www.mozilla.org/js/spidermonkey/

Edit in response to your second question.

I'm not sure exactly what you mean by content generated by a javascript library. You mention ExtJS however, which would imply HTML content I believe?. It's important to understand the difference between the DOM (which Javascript can read and modify but is not "part" of Javascript per se) and Javascript the language. If you need the idea of a DOM server side that's a different story, if you need the Javascript language then the above options should help you out.

束缚m 2024-08-15 14:02:28

Mozilla 的 Rhino JavaScript 引擎非常容易嵌入;它允许 Java 类的子类化和实现接口,以及执行一些快速而肮脏的 JavaScript 对象技巧。几个月来,我一直在闲暇时将其嵌入 GeoServer 中。您可以查看嵌入 Rhino 的 Java 代码以及我们 SVN 存储库中的一些 JavaScript 示例 。 Rhino 还有一个非常好的入门指南

Mozilla's Rhino JavaScript engine is pretty easy to embed; it allows subclassing of Java classes and implementing interfaces, as well as just doing some quick n' dirty JavaScript object trickery. I've been working on embedding it into GeoServer in my off moments for a couple of months now. You can take a look at both the Java code that embeds Rhino and a few JavaScript examples in our SVN repository. Rhino also has a pretty nice guide to getting started.

短暂陪伴 2024-08-15 14:02:28

ASP 和 ASP.NET 支持服务器端 JavaScript。对于 ASP,您所做的就是声明:

<%@LANGUAGE=JAVASCRIPT%>

在 ASP 文件的最顶部,您正在使用 JavaScript 进行编码。 ASP.NET 基本相同,只是您可以访问 .NET 框架。

无法在 Java servlet 方面提供帮助,没有相关经验。

ASP and ASP.NET supports server-side JavaScript. For ASP, all you do is declare:

<%@LANGUAGE=JAVASCRIPT%>

At the very top of the ASP file and you're coding in JavaScript. ASP.NET is basically the same except that you gain access to the .NET framework.

Can't help on the Java servlet front, no experience with it.

停滞 2024-08-15 14:02:28

“Helma 是一个服务器端 Javascript 环境和 Web 应用程序框架,用于快速高效地编写脚本并为您的网站和互联网应用程序提供服务。” - http://helma.org/

"Helma is a server-side Javascript environment and web application framework for fast and efficient scripting and serving of your websites and Internet applications." - http://helma.org/

多情癖 2024-08-15 14:02:28

我拥有在 Windows 环境中使用服务器端 Javascript 的丰富经验。所有 Windows 系统上的 Windows 脚本宿主都提供 Javascript 作为默认语言之一。您可以创建一个 COM 对象,以便通过任何支持 COM 的语言与其进行交互。我认为 此 MSDN 页面 会帮助您如果您想使用这种方法,请开始。

我的直觉是,如果您选择不涉及 COM 的东西,您会更高兴。我只是想确保你有所有的选择。

I have extensive experience using server-side Javascript in a Windows environment. The Windows Scripting Host on all Windows systems provides Javascript as one of the default languages. You can create a COM object to interface with it from any language that supports COM. I think this MSDN page will get you started if you want to use this approach.

My gut feeling is that you'll be happier if you choose something that doesn't involve COM. I just wanted to make sure you had all the options in front of you.

顾忌 2024-08-15 14:02:28

如果您需要做的只是将 HTML 保存为 Excel,那么您可能会更好地将 HTML 发送到服务器,并使用内容处置标头和适当的 MIME 类型返回。服务器端 JS 通常不会实现类似浏览器的 DOM,因此 Ext 无法在服务器端工作。

或者,您可以生成 HTML 服务器端并跳过往返。例如,POI Java 库可以生成具有多个工作表和单元格函数的真正的二进制 Excel 文件。

如果您确实想使用服务器端 JS 作为应用程序服务器,请考虑 Myna。我在这个问题中提到了它的一些优点。

If all you need to do is bless your HTML as Excel, you might be better served sending your HTML to the server and have it served back with a content-disposition header and the appropriate MIME type. Server-side JS doesn't normally implement a browser-like DOM so Ext isn't going to work server-side.

Alternatively you could generate your HTML serverside and skip the roundtrip. For example the POI Java library can generate real binary Excel files with multiple sheets and cell functions.

If you really want to use a server-side JS as your app server, consider Myna. I mentioned in the this question some of its advantages.

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