My form1 looks like this,
<form method="post" id="myform" name="myform" action="upload" enctype="multipart/form-data">
<div id="elements">
<ul id="ul">
<li>Left File : <input type="file" name="dataFile1" id="fileChooser1" /></li><li><br></li>
<li>Right File : <input type="file" name="dataFile2" id="fileChooser2" /></li><li><br></li>
<li>Runner.xlsx : <input type="file" name="dataFile3" id="fileChooser3" /></li><li><br></li>
<li><button type="button" id="execute" onclick="ValidateFile()">Click to Upload files</button></li>
</ul>
</div>
</form>
I've declared a function like this to add hidden data to forms,
function addHidden(theForm, key, value) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = key;
input.value = value;
theForm.appendChild(input);
}
in Validatefile()
var myDivText1 = ace.edit("editor").getValue();
var theForm = document.forms['myform'];
addHidden(theForm, 'mytxt1', myDivText1);
alert(myDivText1);
document.myform.submit();
and in my upload.java servlet,
if (itemField.equals("dataFile1"))
{ //get the text of the editor here and save it
String TEXT = request.getAttribute("mytxt1").toString();//this is being displayed as null
System.out.println(TEXT);
File uploadedFile = new File(fpath, fileName);
item.write(uploadedFile);
String f1 = "<span class='blue'>" + "Uploaded <b>left file</b> " +fileName+ "<br>" + "</span>";
request.setAttribute("f1stat", f1);
}
while the alert in my Javascript function displays correct value, when I try to access this in my upload.java servlet it shows a null value.
I've used this function for another form too which is also it is passing the required data while this one fails, what is my mistake?
I've tried changing getAttribute
to getParameter
still getting Null value.