如何在 servlet 中获取父子复选框的值



我希望将servlet上所有父项和相应子项的值都存储到数据库中。 如何在 servlet 中获取父子复选框的值 请帮忙。 我希望 servlet 上所有父项和相应子项复选框的值都存储到数据库中。 如何在 servlet 中获取父子复选框的值 请帮忙。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<!-- <script type="text/javascript">
$('input[type=checkbox]').click(function(){
// if is checked
if($(this).is(':checked')){
$(this).parents('li').each(function() {
$(this).children('input').prop('checked', true);
});
} else {
// uncheck all children
$(this).parent().find('li input[type=checkbox]').prop('checked', false);
}

</script> -->
<body>
<p>Application Form</p>
<div class="registration">
<form id="createForm" action="NewUserServlet" method="post">
<input type="text" placeholder="Email" name="email"
required="required" /> 
<input type="text" placeholder="password"
name="password" required="required" />
<input type="text"
placeholder="Name" name="name" /><br /><br /> 
<input type="text" placeholder="Mobile number" name="MobNo" />
<select name="role">
<c:forEach items="${RoleList}" var="rolelist">
<option value="${rolelist.roleId}">${rolelist.role}</option>
</c:forEach>
</select><br></br> 
<h5>Select Departments:</h5>
<ul>
<c:forEach items="${DepList}" var="list1">
<li>
<input type="checkbox" value="${list1.did}" name="depp">${list1.dname}<br />
<ul>
<c:forEach items="${BkTypeList}" var="list2">
<li>
<input type="checkbox" value="${list2.typeId}" name="bkTypes">${list2.typeName}<br />
<ul>
<c:forEach items="${OpTypeList}" var="list3">
<li>
<input type="checkbox" value="${list3.otypeId}" name="oTypes">${list3.otypeName}<br />
</li>
</c:forEach>
</ul>
</li>
</c:forEach>
</ul>
</li>
</c:forEach>
</ul>

<input type="submit" name="sub" value="Submit"/>
</form>
</body>
</html>

您必须将表单的操作设置为要发布的网址

然后在服务器代码中,您必须将该 URL 映射到您的 Servlet(您可以在 Web 中执行此操作.xml或者如果您使用标记,则在 Servlet 本身中执行此操作(。然后,你实现 Servlet 的 doPost 方法,并按复选框的名称访问它们:

request.getParameter('depp');

表单中的所有内容都将提交,并且可以如上所示进行捕获。

最新更新