gpt4 book ai didi

servlets - 如何检查复选框是否被选中

转载 作者:行者123 更新时间:2023-12-01 10:46:20 25 4
gpt4 key购买 nike

我在表单上有复选框

<input class="addToFavorite" type="checkbox" name="addToFavorite"> Add to favorite

现在,当表单发布时,我会检查此复选框是否使用此代码进行了检查。但它每次都返回 true。我如何检查复选框是否真的被选中了?

boolean wantAddToFavorites = false;
if (isPayAction) {
wantAddToFavorites = request.getParameter("addToFavorite").equals("on");
}

FireBug 结果

enter image description here

如你所见,它总是发送它的值

最佳答案

如果您想在服务器端检查一个复选框是否被选中,您应该执行以下操作:

1.为您的复选框添加一个值

<input class="addToFavorite" type="checkbox" name="addToFavorite" value="addToFavourite"> Add to favorite</input> 

2.在服务器端勾选这个复选框值

if(request.getParameter("addToFavorite") == null){
//checkbox not checked
}else{
//checkbox checked
}

关于servlets - 如何检查复选框是否被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25401522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com