zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    Tomcat 配置 项目 到tomcat目录外面 和 域名绑定访问(api接口、前端网站、后台管理网站)
    弹窗插件zDialog使用教程
    shiro+spring相关配置
    jQuery分页插件(jquery.page.js)的使用
    ueditor1.4.3配置过程(包含单独上传文件以及图片的使用),ueditor1.4.3上传配置(转 http://www.bkjia.com/webzh/1001016.html)
    ueditor1_4_3_3编辑器修改文章
    jquery获取当前select下拉选的属性值
    js点击标签时获取当前标签属性值
    mysql给root开启远程访问权限,修改root密码
    redis持久化配置
  • 原文地址:https://www.cnblogs.com/SirNie/p/14909292.html
Copyright © 2011-2022 走看看