0

I have my javascript variable ass name array in this i have to print this selected values in to my jsp page.

This is my sample code (For Example):

var namesArray = [];
var checkBoxes = document.querySelectorAll('input[type=checkbox]');
for(var i = 0; i < checkBoxes.length; i++) {
    checkBoxes[i].addEventListener('change', function() {
     if(this.checked){
            console.log(this.value);
namesArray.push(this.value);
console.log(namesArray);
                }
    });
}

tell how to get this var in my jsp and also to use in session......

1 Answer 1

1

you can pass the array to servlet through the query string while submitting and can get the values in servlet using request.getParameterValues

something like

String names[]=  request.getParameterValues("namesArray")
Sign up to request clarification or add additional context in comments.

3 Comments

without the submit button can i get the value from the javascript to my String names[]
if you don't want to submit the whole form..use ajax.
ya sure but i dont know much about ajax can you refer any link for this example or if you have example post it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.