I want to pass a javascript variable to a java servlet. I am developing a web application. This is my html code:
<p id="test">Some text</p>
And this is what i write in the javascript file:
var myVar = document.getElementById('test').innerText;
$.ajax({
url: 'Test',
data: {
myPostVar: myVar
},
type: 'POST'
});
And then this in the servlet (in the doGet):
String result = request.getParameter("myPostVar");
System.out.print(result);
And if i run the Test.java to test, it gives me "null". I googled too much but could not find any solution.