在我的表單中,用戶可以在發帖的形式給Servlet之前檢查幾個複選框:如何在servlet中處理髮布的字符串數組?
<input type="checkbox" class="genre" name="genre[]" value="1"><label for="1">First Person Shooter</label><br>
<input type="checkbox" class="genre" name="genre[]" value="2"><label for="2">Sports</label><br>
<input type="checkbox" class="genre" name="genre[]" value="3"><label for="3">Action/Adventure</label><br>
<input type="checkbox" class="genre" name="genre[]" value="4"><label for="4">Educational</label><br>
<input type="checkbox" class="genre" name="genre[]" value="5"><label for="5">Puzzle</label><br>
<input type="checkbox" class="genre" name="genre[]" value="6"><label for="6">Real Time Strategy</label><br>
<input type="checkbox" class="genre" name="genre[]" value="7"><label for="7">Beat em ups</label><br>
<input type="checkbox" class="genre" name="genre[]" value="8"><label for="8">Survival Horror</label><br>
我表單數據發佈到使用AJAX調用和序列化這樣的表單數據的servlet:
$(".mainSurvey").submit(function(e){
e.preventDefault(); //STOP default action
var postData = $(".mainSurvey").serializeArray();
var botCatcher = $("#botCatcher").val();
if($(".mainSurvey input:checkbox:checked").length > 0 && botCatcher.length == 0){
$.ajax(
{
type: "POST",
url : "DatabaseService",
data : postData,
success: function(data)
{
// continue
},
error: function(jqXHR, textStatus, errorThrown)
{
// handle error
});
}else{
// handle error
}
});
在哪裏我通常會訪問使用文本輸入值:
String input = request.getParameter("input");
如何在發佈後訪問servlet中複選框值的數組?