如何将隐藏字段中的数据从一个jsp页面传递到另一页面? [英] how to pass data in an hidden field from one jsp page to another?

查看:91
本文介绍了如何将隐藏字段中的数据从一个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 

这篇关于如何将隐藏字段中的数据从一个jsp页面传递到另一页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆