[英]How to get whole HTML from a .vm file in Apache Velocity?
I would appreciate your help on my use case. 感谢您对我的用例的帮助。 I have a Servlet which renders some information using javascript in a Apache Velocity template (.vm) file.
我有一个Servlet,它使用Apache Velocity模板(.vm)文件中的javascript呈现一些信息。
Now, before I return this template to the browser, I want to store the entire HTML into my local file system for which I need to access the whole HTML from the .vm template. 现在,在我将此模板返回到浏览器之前,我想将整个HTML存储到我需要从.vm模板访问整个HTML的本地文件系统中。 I am stuck at doing the last step.
我坚持做最后一步。
Web applications are client⟷server applications, meaning that there is a clear separation between the client, which is your browser, and the web server. Web应用程序是client⟷server应用程序,这意味着客户端(即您的浏览器)与Web服务器之间存在明显的分离。 There is no direct connection between the server and the HTML that you see in your browser.
您在浏览器中看到的服务器和HTML之间没有直接连接。
Try to visualize the process: 尝试可视化过程:
.vm
file that should be used to render the response. .vm
文件。 .vm
file is read by the servlet on the server and rendered into a string representation of the HTML. .vm
文件由服务器上的servlet读取,并呈现为HTML的字符串表示形式。 There is no way for the Velocity template (or any other code on the server) to access the HTML that is now in the browser, unless the browser explicitly sends it back to the server in another request. Velocity模板(或服务器上的任何其他代码)无法访问现在在浏览器中的HTML,除非浏览器在另一个请求中明确地将其发送回服务器。
What you can do is: 你能做的是:
click
event. click
事件的JavaScript代码。 var html = document.getElementById('id_of_the_element').innerHTML;
var html = document.getElementById('id_of_the_element').innerHTML;
XMLHttpRequest
, either using the raw XHR support from the browser, or a JS framework of your choice. XMLHttpRequest
将此字符串发送到服务器,使用浏览器的原始XHR支持或您选择的JS框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.