How to transfer data in a hidden field from one jsp page to another?

I have some data in a hidden field on a jsp page

<input type=hidden id="thisField" name="inputName"> 

how to access or transfer this onsubmit field to another page?

+4
source share
2 answers

To pass a value, you must include the hidden value value="hiddenValue" in the <input> statement, for example:

 <input type="hidden" id="thisField" name="inputName" value="hiddenValue"> 

Then you restore the value of the hidden form in the same way as you restore the value of the visible input fields by accessing the parameter of the query object. Here is an example:

This code appears on the page where you want to hide the value.

 <form action="anotherPage.jsp" method="GET"> <input type="hidden" id="thisField" name="inputName" value="hiddenValue"> <input type="submit"> </form> 

Then, on the 'anotherPage.jsp' page, you restore the value by calling the getParameter(String name) method of the implicit request object, like this:

 <% String hidden = request.getParameter("inputName"); %> The Hidden Value is <%=hidden %> 

The output of the above script will be:

 The Hidden Value is hiddenValue 
+11
source

Code from Alex works great. Just keep in mind that when using request.getParameter you must use the request manager

 //Pass results back to the client RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("TestPages/ServiceServlet.jsp"); dispatcher.forward(request, response); 
0
source

Source: https://habr.com/ru/post/1486670/


All Articles