Javascript – retrive hidden input value in jsp scriptlet variable without submit page

javascriptjsp

I have set hidden value in html as below:

<input type="hidden" id="userId" name="userId" value="testUsr"/>

I want this value in jsp scriptlet variable just like below:

<% user %> = docuemnt.getElementById("userId").value;

how can i achieve this ?

Best Solution

This cannot be done. What you need to do is send the value to the servlet either

  1. By passing it in the url
  2. Or sending it as a parameter in the request using the request object in the jsp
  3. Or by placing the hidden field in a <form> and calling a servlet on click of submit like so:

    <form method='get' action='myservlet'>

    <!--Your other fields-->

    <input type="hidden" id="userId" name="userId" value="testUsr"/>

    <input type='submit' value='Submit'/>

    </form>