A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© juanjuan 中级黑马   /  2016-10-9 22:08  /  893 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

请多多指教:
Login.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录图书管理系统 </title>
<style type="text/css">
<!--
.STYLE1 {
        font-size: 36px;
        font-weight: bold;
}
-->
</style>
</head>
<body>
<form name="form1" method="post"  action="valid.jsp">
  <table width="400" height="120" border="1" align="center">
    <caption>
      <span class="STYLE1">登录图书管理系统</span>
    </caption>
    <tr>
      <td width="166">用户名:</td>
      <td width="318"><input name="username" type="text" id="username"></td>
    </tr>
    <tr>
      <td>密码:</td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="Submit" value="登录">
      <input type="reset" name="Submit2" value="取消"></td>
    </tr>
  </table>
</form>
</body>
</html>
Valid.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>判断登录</title>
</head>
<body>
<%       
                String user=request.getParameter("username");
                String pass=request.getParameter("password");
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123456");
                PreparedStatement ps =con.prepareStatement("select * from t_account where username=? and password=?");
                ps.setString(1,user);
                ps.setString(2,pass);
                ResultSet rs = ps.executeQuery();
        if(rs.next()){response.sendRedirect("bookList.jsp");}
        else response.sendRedirect("login.jsp");
%>
</body>
</html>
BookAdd.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加图书信息</title>
<style type="text/css">
<!--
.STYLE1 {
        font-size: 36px;
        font-weight: bold;
}
-->
</style>
</head>
<body>
<form name="form1" method="post" action="bookSaveAdd.jsp">
  <div align="center" class="STYLE1">添加图书信息  </div>
  <table width="300" height="120" border="1" align="center">

    <tr>
      <td width="74">书名:</td>
      <td width="210"><input name="name" type="text" id="name"></td>
    </tr>
    <tr>
      <td>出版社:</td>
      <td><input name="publish" type="text" id="publish"></td>
    </tr>
    <tr>
      <td>价格:</td>
      <td><input name="price" type="text" id="price"></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="Submit" value="确定添加">
      <input type="reset" name="Submit2" value="重置"></td>
    </tr>
  </table>
</form>
</body>
</html>
BookDel.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="3;URL=bookList.jsp">
<title>删除图书</title>
</head>
<body>
<%
                //["3","4","6"]
                String[] ids = request.getParameterValues("ids");
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123456");
                PreparedStatement ps = con.prepareStatement("delete from t_book where id=?");
                for(int i = 0;i<ids.length;i++){
                        ps.setInt(1,Integer.parseInt(ids[i]));
                        ps.execute();
                }
                con.close();
%>
正在删除图书,3秒后自动跳转......
</body>
</html>
bookEdit.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑图书信息</title>
<style type="text/css">
<!--
.STYLE1 {
        font-size: 36px;
        font-weight: bold;
}
-->
</style>
</head>
<body>
<%                String strId = request.getParameter("id");//获取传过来的参数(网络上传输的只能是字符串)
            Class.forName("com.mysql.jdbc.Driver");//java的反射
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123456");
                PreparedStatement ps =con.prepareStatement("select * from t_book where id=?");
                ps.setInt(1,Integer.parseInt(strId));
               
                ResultSet rs=ps.executeQuery();
                if(rs.next()){
%>
<form name="form1" method="post" action="bookSaveEdit.jsp">
<!-- 关键语句 -->
<input type="hidden" name="id" value="<%=rs.getInt("id") %>">
  <div align="center" class="STYLE1">编辑图书信息</div>
  <table width="300" height="120" border="1" align="center">

    <tr>
      <td width="74">书名:</td>
      <td width="210"><input name="name" type="text" id="name" value="<%=rs.getString("name") %>"></td>
    </tr>
    <tr>
      <td>出版社:</td>
      <td><input name="publish" type="text" id="publish" value="<%=rs.getString("publish") %>"></td>
    </tr>
    <tr>
      <td>价格:</td>
      <td><input name="price" type="text" id="price" value="<%=rs.getInt("price") %>"></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="Submit" value="确定修改">
      <input type="reset" name="Submit2" value="取消"></td>
    </tr>
  </table>
</form>
<%
}
con.close();
%>
</body>
</html>
bookList.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑图书信息</title>
<style type="text/css">
<!--
.STYLE1 {
        font-size: 36px;
        font-weight: bold;
}
-->
</style>
</head>
<body>
<%                String strId = request.getParameter("id");//获取传过来的参数(网络上传输的只能是字符串)
            Class.forName("com.mysql.jdbc.Driver");//java的反射
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123456");
                PreparedStatement ps =con.prepareStatement("select * from t_book where id=?");
                ps.setInt(1,Integer.parseInt(strId));
               
                ResultSet rs=ps.executeQuery();
                if(rs.next()){
%>
<form name="form1" method="post" action="bookSaveEdit.jsp">
<!-- 关键语句 -->
<input type="hidden" name="id" value="<%=rs.getInt("id") %>">
  <div align="center" class="STYLE1">编辑图书信息</div>
  <table width="300" height="120" border="1" align="center">

    <tr>
      <td width="74">书名:</td>
      <td width="210"><input name="name" type="text" id="name" value="<%=rs.getString("name") %>"></td>
    </tr>
    <tr>
      <td>出版社:</td>
      <td><input name="publish" type="text" id="publish" value="<%=rs.getString("publish") %>"></td>
    </tr>
    <tr>
      <td>价格:</td>
      <td><input name="price" type="text" id="price" value="<%=rs.getInt("price") %>"></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="Submit" value="确定修改">
      <input type="reset" name="Submit2" value="取消"></td>
    </tr>
  </table>
</form>
<%
}
con.close();
%>
</body>
</html>
bookSaveAdd.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>保存添加</title>
</head>
<body>
<%
//获取提交参数
        String name=request.getParameter("name");
        String pub=request.getParameter("publish");
        String strPr=request.getParameter("price");
        int price=Integer.parseInt(strPr);//数据转换:字符串(数字)转整型
        //利用jdbc完成数据库插入操作
        Class.forName("com.mysql.jdbc.Driver");//java的反射
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123456");
        PreparedStatement ps =con.prepareStatement("insert into t_book(name,publish,price) values(?,?,?)");
        ps.setString(1,name);
        ps.setString(2,pub);
        ps.setInt(3,price);
        ps.execute();
        con.close();
        response.sendRedirect("bookList.jsp");
%>
</body>
</html>
bookSaveEdit.jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>保存编辑</title>
</head>
<body>
<%
        String strId = request.getParameter("id");
        String name=request.getParameter("name");
        String pub=request.getParameter("publish");
        String strPr=request.getParameter("price");
        int price=Integer.parseInt(strPr);//数据转换:字符串(数字)转整型
        int id=Integer.parseInt(strId);
        //利用jdbc完成数据库插入操作
        Class.forName("com.mysql.jdbc.Driver");//java的反射
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123456");
        PreparedStatement ps =con.prepareStatement("update t_book set name=?,publish=?,price=? where id=?");
        ps.setString(1,name);
        ps.setString(2,pub);
        ps.setInt(3,price);
        ps.setInt(4,id);
        ps.execute();
        con.close();
        response.sendRedirect("bookList.jsp");
%>
</body>
</html>

1 个回复

倒序浏览
图书馆系统代码怎么玩?
来自宇宙超级黑马专属苹果客户端来自宇宙超级黑马专属苹果客户端
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马