如何将隐藏字段中的数据从一个jsp页面传递到另一页面?

问题描述:

我在jsp页面上的隐藏字段中有一些数据

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

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

如何在提交时访问或传递此字段到另一个页面?

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

要传递值,必须在<input>语句中包括隐藏值value="hiddenValue",如下所示:

To pass the value you must included the hidden value value="hiddenValue" in the <input> statement like so:

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

然后,通过访问请求对象的参数,以与恢复可见输入字段的值相同的方式恢复隐藏的表单值.这是一个示例:

Then you recuperate the hidden form value in the same way that you recuperate the value of visible input fields, by accessing the parameter of the request object. Here is an example:

此代码在您要隐藏值的页面上显示.

This code goes 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>

然后在"anotherPage.jsp"页面上,通过调用隐式request对象的getParameter(String name)方法来恢复值,如下所示:

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

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

以上脚本的输出为:

The Hidden Value is hiddenValue