Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  35] [ 3]  / answers: 1 / hits: 16049  / 10 Years ago, thu, march 13, 2014, 12:00:00

I've used JavaScript in my JSP page to process get data of the div tag:



var script = ace.edit(editor);
var myDivText = script.getValue();


Now I want to pass myDivText to my servlet.java. Till today I've passed it as below



window.open('http://XXX.XX.XXX.XX:8800/FirstServlet/mygeco?mytxt=' + myDivText,'resizable=yes');


But now, I had to include a few input forms and now I am calling my servlet through a submit mechanism, so how do I pass myDivText to servlet.java without using the above method?



==============================EDIT==========================



My form looks as follows:



<form method=post name=myform action=upload target=_top enctype=multipart/form-data>
<li>Left File : <input type=file name=dataFile1 id=fileChooser1 /></li>
<li>Right File : <input type=file name=dataFile2 id=fileChooser2 /></li>
<li>Config File :<input type=file name=dataFile3 id=fileChooser3 /></li>
<li><input type=hidden name=myField id=myfield value= /></li>
</form>


Submitting form through JavaScript:



var scc1 = document.getElementById(box);
scc1.innerHTML = scc1.innerHTML + <br> + <span class='blue'>Uploading files, the page might refresh</span>;
var thetxt = scc1.innerHTML;
document.getElementById('myField').value = thetxt;
document.myform.submit();


Getting data in Servlet.java



String mydiv = request.getParameter(myField);
request.setAttribute(mydiv, mydiv);

More From » java

 Answers
22

You could give your hidden field an id:



.html file



Your form



<form action=>
<input type=hidden name=myField id=myField value= />
</form>


and then when you want to assign its value:



Your Javascipt



document.getElementById('myField').value = myDivText;


send the form with an action..



And at the action page your retrieve it using request.getParameter(myField)



Hope it helps



UPDATE



Hope this links help
Multipart/form-data how to get parameter hidden



How to upload files to server using JSP/Servlet?


[#72014] Tuesday, March 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;