java 脚本 - 来自 Java 1.5 中服务器端类文件的 javascript

发布于 2024-07-23 09:27:35 字数 782 浏览 11 评论 0原文

我有三种类型的 get 请求,这些请求从移动设备传送到 Web 应用程序上的 class 文件。 因为移动设备不提供 cookie,所以日志文件命中只有

in.ter.nal.ip   ser.ver.i.p:port    2009-06-05  09:14:44    GET /applicationname/mobiledevicexml    reqtype=login&userid=xx###  200 87  -   MercuryMobile/1.0 CFNetwork/342.1 Darwin/9.4.1  cookieArrayLength=0;

如果我可以在类文件中实例化 javascript,并从类文件内部生成对 urchinTracker() 的 javascript 函数调用,我可以替换那个无用的 cookieArrayLength=0; 有了一些有用的数据,海胆就可以从日志文件中读取到分析报告中。 我们一直在研究使用 Rhino 编写 Java 脚本; Safari 书架有:

JavaTM 脚本:语言, 框架和模式

帮助我们立即演示了我们可以在类文件中运行 javascript ——这在 Java 6 上开箱即用。

有人知道在 Java 1.5 或 1.4 上使用 Rhino 编写脚本的任何资源吗?

或者,任何有关从 java 1.5 运行 javascript 的建议将不胜感激。

I have three types of get requests that are delivered to a class file on web application from a mobile device. Because the mobile device provides no cookies, the log file hit only has

in.ter.nal.ip   ser.ver.i.p:port    2009-06-05  09:14:44    GET /applicationname/mobiledevicexml    reqtype=login&userid=xx###  200 87  -   MercuryMobile/1.0 CFNetwork/342.1 Darwin/9.4.1  cookieArrayLength=0;

If I can instantiate javascript in my class file, and generate a javascript function call to urchinTracker() from inside the class file, I can replace that useless cookieArrayLength=0; with some useful data urchin can read from the log file into analytics reports.
We have been looking at scripting in Java with Rhino; Safari Bookshelf has:

Scripting in JavaTM: Languages,
Frameworks, and Patterns

which helped us immediately demo that we can run javascript in class files --this works out-of-the-box on Java 6.

Anyone know any resources for scripting with Rhino on Java 1.5 or 1.4?

Alternately, any suggestions for running javascript from java 1.5 would be appreciated.

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

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

发布评论

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

评论(3

淡笑忘祈一世凡恋 2024-07-30 09:27:36

Java 脚本 API (javax.scripting) 包是在 Java 6 中引入的,因此在 Java 1.4 或 5 中不可用。作为默认安装,Java SE 6 附带了 Mozilla Rhino 的精简版本,该版本通过 javax.scripting

但是,Mozilla Rhino 本身不需要 Java 6。从要求页面:

Rhino 的最新版本仅具有
已使用 JDK 1.4 及更高版本进行了测试。
旧版本很早就支持JDK
如1.1。

因此,要使用Rhino,看来Java 1.4实际上就足够了。

至于资源,Rhino 文档似乎有很多信息。 特别是,嵌入 Rhino 部分可能有助于了解脚本如何工作。

当然,缺少javax.scripting包意味着与Rhino本身的接口将需要使用Rhino API而不是Java 6本机脚本API,但我猜测该功能将会非常相似。 我能看到的唯一缺点是,如果将来目标平台将支持 Java 6 和/或使用其他语言,则可能需要重写以使用 Java 脚本 API,而不是直接支持 Rhino。

The Java Scripting API (javax.scripting) package was introduced in Java 6, so that will not be available in Java 1.4 or 5. As the default installation, Java SE 6 comes with a stripped down version of Mozilla Rhino which is interfaced through javax.scripting.

However, Mozilla Rhino itself does not require Java 6. From the requirements page:

Recent versions of Rhino have only
been tested with JDK 1.4 and greater.
Older versions support JDKs as early
as 1.1.

Therefore, to use Rhino, it appears that Java 1.4 is actually sufficient.

As for resources, the documentation for Rhino seems to have a lot of information. In particular, the Embedding Rhino section might be useful to see how the scripting will work.

Of course, the lack of the javax.scripting package means that interfacing to Rhino itself is going to require the use of the Rhino API rather than the Java 6 native scripting API, but I would guess that the functionality is going to be fairly similar. The only downside I can see is, if in the future, Java 6 is going to be supported on the target platform and/or using another language, it may necessitate a rewrite to use the Java Scripting API rather than directly supporting Rhino.

等风来 2024-07-30 09:27:36

[我在答案中发布,因为我没有足够的积分来对问题本身发表评论。]

您确定 urchinTracker() 函数将在网络浏览器之外运行吗? 如果函数依赖于各种浏览器对象,例如文档对象模型 (DOM) 或 XmlHttpRequest,那么运行 Rhino JavaScript 解释器(这并不太困难)是不够的。

我建议您至少扫描一下 urchinTracker() 函数的内部结构,看看是否是这种情况。

[I'm posting in an answer, because I don't have enough points to post a comment on the question itself.]

Are you sure that the urchinTracker() function will operate outside of a web browser? Running the Rhino JavaScript interpreter (which isn't too difficult) won't be enough if the function relies on various browser objects, like the Document Object Model (DOM) or XmlHttpRequest.

I suggest that you at least scan the internals of the urchinTracker() function to see if this is the case.

孤云独去闲 2024-07-30 09:27:36

有关在服务器端运行 JavaScript 的项目列表,请参阅服务器端 JavaScript

对于您的使用来说,使用 Rhino 似乎是一个不错的选择。

See Server-side JavaScript for list of projects that runs JavaScript at the server-side.

For your usage, using Rhino seems like the way to go.

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