To understand how JSP operates, please see
this article.
document.write isn't the right approach: after page load, it will replace, rather than augment a page. A better approach to augment the DOM is to use the DOM API -- preferably via jQuery which not only makes it easier, but eliminates browser-specific nonsense.
If however, you really need to get a front-end value back to the server, you'll need to submit a request back to the server, either through a form submission or Ajax.