Assign JavaScript variable to Java Variable in JSP

后端 未结 7 1418
猫巷女王i
猫巷女王i 2020-11-30 04:49

Ello there,

I\'m trying to assign the value of a javascript variable to a java variable. But I don\'t have clue how to do this? Say for example I have this:

7条回答
  •  暖寄归人
    2020-11-30 05:32

    Java script plays on browser where java code is server side thing so you can't simply do this.

    What you can do is submit the calculated variable from javascript to server by form-submission, or using URL parameter or using AJAX calls and then you can make it available on server

    HTML

    
    

    make sure this fields lays under

    Javascript

    document.getElementById("hiddenField").value=yourCalculatedVariable;
    

    on server you would get this as a part of request

提交回复
热议问题