简体   繁体   English

如何通过Java(从服务器)通过Java更改显示的HTML页面的DOM?

[英]How do I mutate the DOM of a displayed HTML page, via Java, over HTTP (from the server)?

I would like to get a reference to the DOM of a displayed webpage so that I can add and remove elements. 我想参考所显示网页的DOM,以便可以添加和删除元素。 I would like to add and remove those elements by sending HTTP requests from, say, a servlet. 我想通过从servlet发送HTTP请求来添加和删除这些元素。 Further, I would like to be able to construct a DOM, node-by-node, in the browser, via java, from http messages coming from said servlet. 此外,我希望能够在浏览器中通过Java根据来自所述servlet的http消息来逐节点构造DOM。

Suppose someone requests a url (say): http://helloWorld.xhtml 假设有人请求一个网址(例如): http://helloWorld.xhtml

I would like to render the content by sending HTTP messages, which, node by node, build the displayed document. 我想通过发送HTTP消息来呈现内容,该HTTP消息逐节点构建显示的文档。 Then, if I need to change something in the document, I would like to be able to remove html node-wise, or add html in the same manner; 然后,如果需要更改文档中的某些内容,则希望能够逐节点删除html或以相同的方式添加html; I would like to make partial changes to the html document via http. 我想通过http对html文档进行部分更改。

Does anybody know of specific way(s) to accomplish this? 有人知道实现此目标的具体方法吗?

I don't want to use JavaScript, unless it means a utility method to accomplish the communication mechanism only. 我不想使用JavaScript,除非它意味着仅用于完成通信机制的实用程序方法。 I don't want to use a client-side applet either, but that might be a way of getting around the limitations of http (ie, sending back java object responses via jaxb). 我也不想使用客户端小程序,但这可能是解决http局限性的一种方法(即通过jaxb发回Java对象响应)。


I don't want to use javascript because I just want to use an html browser as a displayer of elements that relay the occurence of events back to the server. 我不想使用javascript,因为我只想使用html浏览器作为将事件的发生中继回服务器的元素的显示器。 Then, I want to be able to add or remove elements without redrawing the page. 然后,我希望能够在不重绘页面的情况下添加或删除元素。 Also, I would like to use XSLT to generate HTML, but again, I would like a way of updating the web page without using hidden elements and without redrawing the whole page. 另外,我想使用XSLT生成HTML,但是,我仍然想一种不使用隐藏元素也不重绘整个页面的更新网页的方法。

I thought of something else also. 我也想到了别的东西。 I might use a JApplet embedded in an HTML page, and then just communicate with the JApplet via JAXB? 我可能会使用嵌入在HTML页面中的JApplet,然后仅通过JAXB与JApplet通信? I am assuming that you can do that.. (maybe it does not work that way). 我假设您可以这样做..(也许它不能那样工作)。 Then, in the JApplet, just using a means of displaying an HTML page; 然后,在JApplet中,仅使用一种显示HTML页面的方法; there might be a better option amongst the components than the JLabel. 组件之间可能有比JLabel更好的选择。

I think that the best option would either be using the HTTP mechanism (if possible) or else, using some sort of middle layer that would enable me to send Java back and forth between the webpage and the server. 我认为最好的选择要么是使用HTTP机制(如果可能),要么是使用某种中间层,该中间层使我能够在网页和服务器之间来回发送Java。


I've thought about this a minute, and perhaps, if browsers would change their update policy, then, we would be able to use http to facilitate a view that is updateable on a per-element basis, via a browser behavior that supports additions or subtractions of elements? 我已经考虑了这一分钟,也许,如果浏览器会更改其更新策略,那么我们将能够使用http来促进通过支持添加功能的浏览器行为对每个元素进行更新的视图。或元素减去?

Why you don't want to use JS is beyong me since this is THE language for editing the dom. 为什么我不想使用JS呢,因为这是用于编辑dom的语言。

The easiest way to accomplish your scenario would be using Jquery.ajax . 完成场景的最简单方法是使用Jquery.ajax

For parsing/building Json i would recommend Google's Gson . 对于解析/构建Json,我建议使用Google的Gson

You can look here for a small sample. 您可以在这里寻找一个小样本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM