无法从JSP检索多个检查值 [英] failing to retrieve multiple checked value from JSP
问题描述
我正在尝试检索多个检查值,这些值在JSP中动态显示,是从邮件服务器的收件箱文件夹中检索的,就像在yahoo或gmail中一样.但是,每当我选择多个复选框(或其中一个)时,我都无法检索它们的值,例如主题和用户名.我应该在JSP中做些什么才能动态地在另一个JSP中检索那些值?
I'm trying to retrieve mulitple checked value, which are being showed in JSP dynamically, retrieved from inbox folder of the mail server, just like in yahoo, or gmail. But whenever I select multiple checkboxes(or either one), I'm not able to retrieve their values, like subject and username. What should I have to do in JSP to retrieve those values in another JSP dynamically?
推荐答案
表单中的每个复选框应具有相同的名称,但应具有不同的值.例如
Each check-box in a form should have the same name but different value. e.g.
...
<input
type="checkbox"
id="SELECT_CB_1"
name="SELECT_CB"
value="1"
/> Checkbox 1
<input
type="checkbox"
id="SELECT_CB_2"
name="SELECT_CB"
value="2"
/> Checkbox 2
<input
type="checkbox"
id="SELECT_CB_3"
name="SELECT_CB"
value="3"
/> Checkbox 3
...
然后,当您发布表单时,可以使用HttpServletRequest
检索名称为SELECT_CB
的所有复选框的值.
Then when your form gets posted, you can use HttpServletRequest
to retrieve the values of all checked boxes with the name SELECT_CB
.
String[] checked_values = request.getParameterValues( "SELECT_CB" );
如果未选中任何复选框,则可能需要检查null
.
You may need to check for null
if no checkboxes are selected.
在前面的示例中,如果选中SELECT_CB_1
和SELECT_CB_3
,则checked_values
将包含[ "1", "3" ]
In the previous example, if you check SELECT_CB_1
and SELECT_CB_3
then checked_values
will contain [ "1", "3" ]
您可以使用这些值来检索难题的其他部分,例如主题和用户名.
You can use these values then to retrieve other pieces of your puzzle, like subject and username.
这篇关于无法从JSP检索多个检查值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!