title: Passing variable from JavaScript to servlet
body: <p>I've used JavaScript in my JSP page to process get data of the div tag:</p>
  
  <pre><code>var script = ace.edit("editor");
  var myDivText = script.getValue();
  </code></pre>
  
  <p>Now I want to pass myDivText to my <code>servlet.java</code>. Till today I've passed it as below</p>
  
  <pre><code>window.open('http://XXX.XX.XXX.XX:8800/FirstServlet/mygeco?mytxt=' + myDivText,'resizable=yes');
  </code></pre>
  
  <p>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?</p>
  
  <p>==============================EDIT==========================</p>
  
  <p>My form looks as follows:</p>
  
  <pre><code>&lt;form method="post" name="myform" action="upload" target="_top" enctype="multipart/form-data"&gt;
  &lt;li&gt;Left File :  &lt;input type="file" name="dataFile1" id="fileChooser1" /&gt;&lt;/li&gt;
  &lt;li&gt;Right File : &lt;input type="file" name="dataFile2" id="fileChooser2" /&gt;&lt;/li&gt;
  &lt;li&gt;Config File :&lt;input type="file" name="dataFile3" id="fileChooser3" /&gt;&lt;/li&gt;
  &lt;li&gt;&lt;input type="hidden" name="myField" id="myfield" value="" /&gt;&lt;/li&gt;
  &lt;/form&gt;
  </code></pre>
  
  <h3>Submitting form through JavaScript:</h3>
  
  <pre><code>var scc1 = document.getElementById("box");
  scc1.innerHTML = scc1.innerHTML + "&lt;br&gt;" + "&lt;span class='blue'&gt;Uploading files, the page might refresh&lt;/span&gt;";
  var thetxt = scc1.innerHTML;
  document.getElementById('myField').value = thetxt; 
  document.myform.submit();   
  </code></pre>
  
  <h3>Getting data in Servlet.java</h3>
  
  <pre><code>String mydiv = request.getParameter("myField");
  request.setAttribute("mydiv", mydiv);
  </code></pre>