Search code examples
javascriptjavajqueryjspscriptlet

How to receive "hidden field" values in second jsp


I have page1.jsp where hidden fields are included. Following is the code:

<form action = "page2.jsp" method = "post" id = "hiddenValuesForm">
<input type = "hidden" name = "userData" value="" id = "useDataID">
<input type = "SUBMIT" id= "submitUserData" style= "display:none" >
</form>

In page2.jsp , I can get the hidden field values using the below code:

<%
String hiddenField = request.getParameter("userData");
%>

Is there any way I can assign the value of "userData" to a jquery variable in page2.jsp similar to the scriplet variable "hiddenField".


Solution

  • You can generate a javascript variable in page2.jsp:

    <script>
    var myUserData="<%=request.getParameter("userData")%>"
    </script>
    

    (I put enclosing quotes assuming it is a string.)