3

How exactly is Javascript code generated in Direct Web Remoting (DWR)? I have gone through the official site http://directwebremoting.org as well as other sources (http://directwebremoting.org/dwr/introduction/scripting-dwr.html) and understand there are 3 JS files.

But my question is; how is the JS generated and is it possible to make changes/customize any of the functions? If yes, how?

Thank you.

4

1 回答 1

2

您可以检查这些文件以更好地理解,但它们的作用类似于管道。如果您将自定义代码分开,则可维护性会更好。

“engine.js”和“util.js”文件位于 DWR jar 的文件夹中:org/directwebremoting。engine.js 文件包含一些${...}变量,这些变量在文件发送到浏览器之前会被 servlet 替换。util.js 文件不包含此类变量。

接口文件比较复杂。我从来不需要进行更改或自定义这些(实际上这是 DWR 部分的好设计)。我的猜测是,基于接口的 js 文件是由您在 dwr.xml 中配置的内容生成的,并且 DWR 使用反射 API 来读取 Java 帮助程序类并生成一个 Javascript-stub 以映射到它。<script src=".../dwr/interface/filename.js">您可以通过将您的 URL 粘贴到不同的浏览器选项卡中来查看这些文件。

于 2011-04-19T13:19:23.250 回答