• 2021.5.14


    三--3

    edit:

    <%@ page import="java.sql.*" pageEncoding="utf-8" errorPage="error.jsp"%>
    <html>
    <head>
    <title>修改学生信息</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
    <body>
    <%
    request.setCharacterEncoding("utf-8");
    String id = request.getParameter("id");
    Class.forName("com.mysql.cj.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false", "root", "123456");
    //Statement stmt = con.createStatement();
    //ResultSet rs = stmt.executeQuery("select * from bookinfo where id=" + id);

    PreparedStatement stmt = con.prepareStatement("select * from studentinfo where num=?");
    stmt.setString(1, id);
    ResultSet rs = stmt.executeQuery();

    rs.next();
    %>
    <form action="editsave.jsp" method="post" onsubmit="return dosubmit();">
    <h2>修改学生信息</h2>
    <table style="50%">
    <tr>
    <th width="30%">学号:</th>
    <td width="70%"><input name="stunum" type="text"
    value="<%=rs.getInt(1)%>"></td>
    </tr>
    <tr>
    <th>姓名:</th>
    <td><input name="stuname" type="text"
    value="<%=rs.getString(2)%>"></td>
    </tr>
    <tr>
    <th>性别:</th>
    <td>
    <%
    if(rs.getString(3).equals("男")){
    out.print("<input type='radio' name='sex' value='男' checked>男");
    out.print("<input type='radio' name='sex' value='女'>女");
    }else{
    out.print("<input type='radio' name='sex' value='男'>男");
    out.print("<input type='radio' name='sex' value='女' checked>女");
    }
    %>
    </td>
    </tr>
    <tr>
    <th>出生日期:</th>
    <td><input name="birthday" type="text"
    value="<%=rs.getString(4)%>"></td>
    </tr>
    <tr>
    <th>家庭住址:</th>
    <td><input name="location" type="text"
    value="<%=rs.getString(5)%>"></td>
    </tr>
    <tr>
    <td colspan="2"><input type="hidden" name="id" value="<%=id%>">
    <input type="submit" value="修改"> <input type="reset"
    value="重置"></td>
    </tr>
    </table>
    </form>
    <%
    rs.close();
    stmt.close();
    con.close();
    %>
    <script type="text/javascript" src="./js/dataCheck.js"></script>
    </body>
    </html>

    editsave:

    <%@ page import="java.sql.*" pageEncoding="utf-8" errorPage="error.jsp"%>
    <html>
    <head>
    <title>修改完成</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
    <body>
    <%
    request.setCharacterEncoding("utf-8");
    String id = request.getParameter("id");
    String stunum = request.getParameter("stunum");
    String stuname = request.getParameter("stuname");
    String sex = request.getParameter("sex");
    String birthday = request.getParameter("birthday");
    String location = request.getParameter("location");
    Class.forName("com.mysql.cj.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false", "root", "123456");
    Statement stmt = con.createStatement();
    String sql = "update studentinfo set num='" + stunum + "',name='" + stuname + "',sex='" + sex + "',birthday='" + birthday + "',location='"+location+
    "' where num='" + Integer.valueOf(id)+"';";
    int i = stmt.executeUpdate(sql);
    if (i == 1) {
    out.println("<h2>修改成功!</h2><br/>");
    out.println("<a href='index.jsp'>返回首页</a>");
    } else {
    out.println("<h2>修改失败!</h2><br/>");
    out.println("<a href='edit.jsp?id='" + stunum + ">重新添加</a>");
    }
    stmt.close();
    con.close();
    %>
    </body>
    </html>

  • 相关阅读:
    html 中 #include file 的用法
    人人网FED CSS编码前端开发规范
    (转载)css垂直水平居中的整理
    CSS负边距自适应布局三例
    (转载)无缝滚动图片的js和jquery两种写法
    用css3实现鼠标移进去当前亮其他变灰
    应急响应
    扫描工具介绍
    入侵检测
    安全防护与加固
  • 原文地址:https://www.cnblogs.com/SirNie/p/14909292.html
Copyright © 2020-2023  润新知