How can i access javascript variables in JSP?

后端 未结 3 736
谎友^
谎友^ 2020-11-30 12:52

I want to access Javascript variables in JSP code. How can I do that?

3条回答
  •  粉色の甜心
    2020-11-30 13:20

    JavaScript variable is on client side, JSP variables is on server side, so you can't access javascript variables in JSP. But you can store needed data in hidden fields, set its value in client and get it on server over GET or POST.

    Client side:

    
    

    server side:

    <%
    if (request.getParameter("data") != null) { %>
     Your value: <%=request.getParameter("data")%>
    <%   
    } 
    %>
    

提交回复
热议问题