练习小Demo-----学生信息管理系统

初次做的一个小Demo

技术点:使用servlet、Tomcat、mysql、jdbc工具、jsp、EL/jstl表达式、三层架构

知识点描述:练习后台的增删改查/用户的

遇到的第一个问题点描述:在页面上使用复选框进行批量删除数据库的信息。一直报空指针异常,未捕捉到复选框中的数据

问题解决点:

jsp页面

<script>

function delMoreStudent(){

var isDel = confirm("您确定所选的吗?");
if(isDel){
//删除
location.href = "${pageContext.request.contextPath}/delMoreStudent";
}

}

</script>

<form id="Form1" name="Form1"  action="${pageContext.request.contextPath}/delMoreStudent"  method="post">

<input type="submit" value="删除" onclick="delMoreStudent()">

<c:forEach items="${stuInfoList }" var="stuInfo" varStatus="vs">

<tr>

<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="11%">${vs.count }</td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="11%">
<imgwidth="40"height="40"style="border-radius:50%"src="${pageContext.request.contextPath}/${stuInfo.getSimage() }">
</td>

<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="11%">${stuInfo.getSname() }</td>

...............................

<td align="center" style="HEIGHT: 22px">

<input type="checkbox" name="checkone" value="${stuInfo.sid}"/>
</td>
</tr>

</c:forEach> 

数据处理:

web层关键代码:

String[] ids = (String[])request.getParameterValues("checkone");

Dao层关键代码:

for (int i = 0; i < ids.length; i++) {
String sql = "delete from studentsinfo where sid=?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, ids[i]);
pst.executeUpdate();
}

猜你喜欢

转载自blog.csdn.net/jinchunzhao123/article/details/80927829