0
I pass a value to Servlet, with js, not to redirect the page:
var formData = new FormData();
var xhr = new XMLHttpRequest();
xhr.open('POST', 'ServletMessage', true);
xhr.send(formData);
and write this value in the database, the problem is that the page refreshes before writing in the comic, and the value does not change on the screen. How can I expect Servlet to record in the database, and then refresh the page?
How do I receive this value in Servlet, for example a text field? I’m trying, but it always comes null.
– Thiago R.
I modified my answer by including an example. In your code,
formData
was initialized but was sent without setting any value.– rodorgas
How do I call this function? and I can add an array of files?
– Thiago R.
To attach a file is used
FormData
same. To use this code block, you have to create the function first. From there, you specify the function in the event of an element directly or use theaddEventListener
(recommended).– rodorgas