mysql+tomcat+jsp增删改查(四)

update.jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ page import="java.sql.*"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>学生信息</title>

    

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

 <script type="text/javascript"">

    function validate()

    {

    var id = document.forms[0].id.value;

    var name = document.forms[0].name.value;

    var age = document.forms[0].age.value;

    var major = document.forms[0].major.value;

    if(id <= 0){

     alert("学号不能为空,请输入学号!");

     return false;

    }

    else if(name.length <= 0){

     alert("姓名不能为空,请输入姓名!");

     return false;

    }

    else if(age <= 0){

     alert("请输入合法年龄!");

     return false;

    }

 

        else if(major.length <= 0){

     alert("专业不能为空,请输入所学专业!");

     return false;

    }

 

    else{

     return true;

    }

     //document.getElementById("form").submit();

    }

    function checkName(sName)

{

  return "李王张刘陈杨赵黄周吴徐孙胡朱高林何郭马罗梁宋郑谢韩唐冯于董萧程曹袁邓许傅沈曾彭吕苏卢蒋蔡贾丁魏薛叶阎余潘杜戴夏钟汪田任姜范方石姚谭廖邹熊金陆郝孔白崔康毛邱秦江史顾侯邵孟龙万段章钱汤尹黎易常武乔贺赖龚文庞樊兰殷施陶洪翟安颜倪严牛温芦季俞章鲁葛伍韦申尤毕聂丛焦向柳邢路岳齐沿梅莫庄辛管祝左涂谷祁时舒耿牟卜路詹关苗凌费纪靳盛童欧甄项曲成游阳裴席卫查屈鲍位覃霍翁隋植甘景薄单包司柏宁柯阮桂闵欧阳解强柴华车冉房".indexOf(sName[0])

}

    </script>

  </head>

  

  <body background="pic/background.jpg">

 <%

    response.setCharacterEncoding("UTF-8");

    request.setCharacterEncoding("UTF-8");

    String id = request.getParameter("id");

    Connection conn = null;

    Statement stat = null;

    ResultSet rs = null;

    Class.forName("com.mysql.jdbc.Driver");

    String url = "jdbc:mysql://localhost:3306/jsp";

    String user = "root";

    String password = "root";

    conn = DriverManager.getConnection(url,user,password);

    stat = conn.createStatement();

    rs = stat.executeQuery("select * from student where id=" + id + "");

  %>

  <br>

    <h2>学生信息</h2>  <hr>    

    <br>

  <h3>要修改的学生信息如下</h3>

   <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt">

    <tr>

    <td>学号</td>

    <td>姓名</td>

    <td>年龄</td>

    <td>性别</td>

    <td>专业</td>

    </tr>

    <%

    while(rs.next())

    {

    out.print("<tr>");

    out.print("<td>" + rs.getInt("id") + "</td>");

    out.print("<td>" + rs.getString("name") + "</td>");

    out.print("<td>" + rs.getInt("age") + "</td>");

    out.print("<td>" + rs.getString("gender") + "</td>");

    out.print("<td>" + rs.getString("major") + "</td>");

    out.print("</tr>");

  

  

    %>

      </table>

      

      <br>

         <br>

 <h3>将学生信息更改为:</h3>

 <form action="updateShow.jsp" method="post" onSubmit="return validate()">

<h4> 学号:<input type="text" name="id" value="<%=rs.getInt("id") %>" title="学号不能改变" readonly="readonly"></input><br></h4>

<h4>  姓名:<input type="text" name="name" title="姓名不能为空" onclick="return checkName(name)"></input><br></h4>

<h4>  年龄:<input type="text" name="age" title="年龄不能为空"></input><br></h4>

<h4>  性别:<input type="radio" name="gender" value="">

       <input type="radio" name="gender" value=""><br></h4>

<h4>  专业:<input type="text" name="major" title="专业不能为空"></input><br></h4>

 <input type="submit" value="修改"/>

  </form>

 

 <br>

<h3><a href=addStuInfo.jsp>返回添加信息页面</a></h3>

<h3><a href=showInfo.jsp>返回信息查询页面</a></h3>

<%

  }

 %>

      <%

    if(rs != null)

    {

        rs.close();

        rs = null;

    }

        if(stat != null)

    {

        stat.close();

        stat = null;

    }

        if(conn != null)

    {

        conn.close();

        conn = null;

    }

    %>

   

  </body>

</html>

 

 

updateShow.jsp

 

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ page import="java.sql.*"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>学生信息</title>

    

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

 <script type="text/javascript"">

    function validate()

    {

    var id = document.forms[0].id.value;

    var name = document.forms[0].name.value;

    var age = document.forms[0].age.value;

    var major = document.forms[0].major.value;

    if(id <= 0){

     alert("学号不能为空,请输入学号!");

     return false;

    }

    else if(name.length <= 0){

     alert("姓名不能为空,请输入姓名!");

     return false;

    }

    else if(age <= 0){

     alert("请输入合法年龄!");

     return false;

    }

 

        else if(major.length <= 0){

     alert("专业不能为空,请输入所学专业!");

     return false;

    }

 

    else{

     return true;

    }

     //document.getElementById("form").submit();

    }

    function checkName(sName)

{

  return "李王张刘陈杨赵黄周吴徐孙胡朱高林何郭马罗梁宋郑谢韩唐冯于董萧程曹袁邓许傅沈曾彭吕苏卢蒋蔡贾丁魏薛叶阎余潘杜戴夏钟汪田任姜范方石姚谭廖邹熊金陆郝孔白崔康毛邱秦江史顾侯邵孟龙万段章钱汤尹黎易常武乔贺赖龚文庞樊兰殷施陶洪翟安颜倪严牛温芦季俞章鲁葛伍韦申尤毕聂丛焦向柳邢路岳齐沿梅莫庄辛管祝左涂谷祁时舒耿牟卜路詹关苗凌费纪靳盛童欧甄项曲成游阳裴席卫查屈鲍位覃霍翁隋植甘景薄单包司柏宁柯阮桂闵欧阳解强柴华车冉房".indexOf(sName[0])

}

    </script>

  </head>

  

  <body background="pic/background.jpg">

 <%

    response.setCharacterEncoding("UTF-8");

    request.setCharacterEncoding("UTF-8");

    String id = request.getParameter("id");

    Connection conn = null;

    Statement stat = null;

    ResultSet rs = null;

    Class.forName("com.mysql.jdbc.Driver");

    String url = "jdbc:mysql://localhost:3306/jsp";

    String user = "root";

    String password = "root";

    conn = DriverManager.getConnection(url,user,password);

    stat = conn.createStatement();

    rs = stat.executeQuery("select * from student where id=" + id + "");

  %>

  <br>

    <h2>学生信息</h2>  <hr>    

    <br>

  <h3>要修改的学生信息如下</h3>

   <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt">

    <tr>

    <td>学号</td>

    <td>姓名</td>

    <td>年龄</td>

    <td>性别</td>

    <td>专业</td>

    </tr>

    <%

    while(rs.next())

    {

    out.print("<tr>");

    out.print("<td>" + rs.getInt("id") + "</td>");

    out.print("<td>" + rs.getString("name") + "</td>");

    out.print("<td>" + rs.getInt("age") + "</td>");

    out.print("<td>" + rs.getString("gender") + "</td>");

    out.print("<td>" + rs.getString("major") + "</td>");

    out.print("</tr>");

  

  

    %>

      </table>

      

      <br>

         <br>

 <h3>将学生信息更改为:</h3>

 <form action="updateShow.jsp" method="post" onSubmit="return validate()">

<h4> 学号:<input type="text" name="id" value="<%=rs.getInt("id") %>" title="学号不能改变" readonly="readonly"></input><br></h4>

<h4>  姓名:<input type="text" name="name" title="姓名不能为空" onclick="return checkName(name)"></input><br></h4>

<h4>  年龄:<input type="text" name="age" title="年龄不能为空"></input><br></h4>

<h4>  性别:<input type="radio" name="gender" value="">

       <input type="radio" name="gender" value=""><br></h4>

<h4>  专业:<input type="text" name="major" title="专业不能为空"></input><br></h4>

 <input type="submit" value="修改"/>

  </form>

 

 <br>

<h3><a href=addStuInfo.jsp>返回添加信息页面</a></h3>

<h3><a href=showInfo.jsp>返回信息查询页面</a></h3>

<%

  }

 %>

      <%

    if(rs != null)

    {

        rs.close();

        rs = null;

    }

        if(stat != null)

    {

        stat.close();

        stat = null;

    }

        if(conn != null)

    {

        conn.close();

        conn = null;

    }

    %>

   

  </body>

</html>

 

 

整个结构如下:

 

 

p24

 

接下就进行最后一步了。

 

我们要下载一个驱动mysql-conn-java-5.1.20zip文件包


 

下载第二个、保存。

 

解压之后找到类似于这样的jar文件

复制到normal下面的WEB-INF下的lib文件夹中,一切搞定

 

打开tomcat文件夹的bin文件夹

 

找到  startup.bat  双击打开

打开浏览器

 

在地址栏输入http://localhost:808/normal/


结果界面如上,然后自己去熟悉一下吧.

楼主QQ:496056171

阅读更多
换一批

没有更多推荐了,返回首页