I have an editor, in which all the user entered text is entered into a tag, now I want to pass this data to a servlet. I've tried using forms but, the value on the servlet side displays a null.
How to do it? and I want to get this data into my doget().
JSP
<form method="post" name="divdata" action="mygeco" target="_blank" >
<div id="editor">
User enters some text here
</div></form>
<button type= "button" style="position: absolute; right: 11%; top: 30%;" id="execute" onclick="saveTextAsFile()">Click to execute</button>
<script type='text/javascript'>
function saveTextAsFile()
{
document.divdata.submit();
}
Servlet:
String text = request.getParameter("divdata");
System.out.println(text);
PS: I've also tried passing by url, but this is creating me further problems, apart from this pl suggest if there is any other method.
window.open('http://XXX.XX.XXX.XXX:7774/FirstServlet/mygeco?mytxt=' + myDivText,'_top','resizable=yes');
i think what you got to do is like the following :
1st - declare your ACE editor with the div like the following :
<body onload="onloadPage()">
<form method="post" id="divdata" action="mygeco" target="_blank" >
<div id="editor">
User enters some text here
</div>
<textarea id="textArea" ></textarea>
<input type="button" onclick="submitForm()" value="Button"/>
</form>
</body>
2nd - onloadPage() :
function onloadPage()
{
// hide the textArea
document.getElementById('textArea').style.display = "none";
}
3rd - submitForm() :
function submitForm() {
var editor = ace.edit("editor");
var code = editor.getSession().getValue();
document.getElementById('textArea').style.display = "block";
document.getElementById('textArea').value=code;
document.getElementById("divdata").submit();
}
4th - get the value in the servlet :
String textArea=request.getParameter("textArea");
and please give me feedback .
Hope that helps .