deleteStudentjsp.jsp页面代码
<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> DELETE STUDENT</title> </head> <body> <table style="border-right:#89d4f8 1px solid; border-top:#89d4f8 1px solid; border-left:#89d4f8 1px solid" cellSpacing=0 cellpadding=70 align=center bgColor=#ffffff border=0> <tbody> <tr> <td height=26> 删除学生信息</td> </tr> <tr> <td height=1 bgColor=#89d4f8> </td> </tr> </tbody> </table> <!-- 以post方式提交数据 --> <form name="messages" method="post" action="after_deleteStudent.jsp"> <table width="50" align="center" border="0"> <tr> <td height=26> </td> </tr> <tr> <td width="267">按学号删除: </td> <td><input type="text"name="StuID"></td> </tr> <TR> <td width="67"></td> <td><input type="submit"value="删除"></td> </TR> </table> </form> </body> </html>
after_deleteStudent.jsp代码
<%@ page language="java" import="java.util.*" import="com.mysql.jdbc.Driver" import="java.sql.*" contentType="text/html;charset=gb2312" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>after_deleteStudent</title> </head> <body> <% Connection conn; Statement stat; //设置连接的url,其中student是数据库名称 String url="jdbc:mysql://localhost:3306/student"; //我使用的是免安装版的mysql,用户:root,密码:zhangweijie String userName="root"; String password="zhangweijie"; //获取deleteStudentjsp.jsp页面post过来的StuID int StuID=Integer.parseInt(request.getParameter("StuID")); try{ //注册JDBC驱动程序 Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException ex){ out.println("找不到驱动程序!"); } //打开数据库连接 conn=DriverManager.getConnection(url, userName, password); try{ stat=conn.createStatement(); //执行删除操作 int isOK=stat.executeUpdate("delete from Student_Info where StuID="+StuID+""); if(isOK>0) { out.println("删除成功!"); } } catch(SQLException ex){ out.println("删除失败!"); } finally{ conn.close(); } %> </body> </html>
JSP--TOMCAT-MYSQL web页面删除,布布扣,bubuko.com
原文:http://www.cnblogs.com/yuhuameng/p/3750146.html