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.
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. 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. There is no direct connection between the server and the HTML that you see in your browser.
Try to visualize the process:
.vm
file that should be used to render the response..vm
file is read by the servlet on the server and rendered into a string representation of the 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.
What you can do is:
click
event.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.