zoukankan      html  css  js  c++  java
  • JSP--TOMCAT-MYSQL web页面删除

    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>&nbsp;&nbsp;删除学生信息</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>&nbsp;&nbsp;&nbsp;</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>
  • 相关阅读:
    思维导图 第八章 项目质量管理
    思维导图 第七章 项目成本管理
    redis安装与配置
    思维导图 第六章 项目进度管理
    思维导图 第五章 项目范围管理
    Linux下用户-组权限配置
    意灵魔法馆首页的初步设计
    try catch自定义异常类的使用
    使用freemarker时,生成的html出现乱码
    乱码问题
  • 原文地址:https://www.cnblogs.com/yuhuameng/p/3750146.html
Copyright © 2011-2022 走看看