我现在想实现 点击表格中的某一行 然后再点击删除按钮,可以直接删除某条数据,但是现在拿到id一直报错,求大神指导
这是servlet中的代码
private void delete(HttpServletRequest request, HttpServletResponse response) {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int id =Integer.parseInt(request.getParameter("id")); //这一行报错,错误是java.lang.NumberFormatException: null
boolean flag=dao.delete(id);
if(flag){
try {
PrintWriter outt = response.getWriter();
outt.print("<script>alert('删除成功!');window.location.href='student?type=show';</script>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
try {
PrintWriter outa = response.getWriter();
outa.print("<script>alert('删除失败!');window.location.href='student?type=show';</script>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这是dao层的代码
public boolean delete(int id){
boolean flag= false;
Connection connection=null;
PreparedStatement preparedStatement=null;
String sql ="delete from student where id = ?;";
try {
Class.forName("com.mysql.jdbc.Driver");
connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/school","root","root");
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setInt(1, id);
int result=preparedStatement.executeUpdate();
if(result>0){
flag=true;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
这是jsp页面中的获取id的代码
$(document).ready(function(){
var selectId=0;
$("#modify").click(function(){
window.location.href="student?type=showModify&id="+selectId+"";
});
$("tr").click(function(){
$("tr").removeClass("info");
$(this).addClass("info");
selectId=$(this).data("id");
});
});
求大神指导。。!!!!