库存物资管理系统

package com.hjf.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 数据库连接工具
 * @author Hu
 *
 */
public class DBUtil {

    public static String db_url = "jdbc:mysql://localhost:3306/course";
    public static String db_user = "root";
    public static String db_pass = "root";

    public static Connection getConn () {
        Connection conn = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");//加载驱动
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return conn;
    }

    /**
     * 关闭连接
     * @param state
     * @param conn
     */
    public static void close (Statement state, Connection conn) {
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close (ResultSet rs, Statement state, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws SQLException {
        Connection conn = getConn();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql ="select * from course";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        if(rs.next()){
            System.out.println("空");
        }else{
            System.out.println("不空");
        }
    }
}

add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
    <%
         Object message = request.getAttribute("message");
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">库存物资录入</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=add" method="post" onsubmit="return check()">
            <div class="a">
                物资名称<input type="text" id="name" name="name"/>
            </div>
            <div class="a">
                生产厂家<input type="text" id="teacher" name="teacher" />
            </div>
            <div class="a">
                型号<input type="text" id="classroom" name="classroom" />
            </div>
            <div class="a">
                入库日期<input type="text" id="date" name="date" />
                </div>
                <div class="a">
                规格<input type="text" id="size" name="size" />
                </div>
                <div class="a">
                数量<input type="text" id="amount" name="amount" />
                </div>
                <div class="a">
                送货人<input type="text" id="give" name="give" />
                </div>
                <div class="a">
                出库日期<input type="text" id="out" name="out" />
                </div>
            <div class="a">
                <button type="submit" class="b">保&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;存</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");;
            var teacher = document.getElementById("teacher");
            var classroom = document.getElementById("classroom");
            var date = document.getElementById("date");
            var size = document.getElementById("size");
            var amount = document.getElementById("amount");
            var out = document.getElementById("out");
            var give = document.getElementById("give");
            //非空
            if(name.value == ‘‘) {
                alert(‘物资名称为空‘);
                name.focus();
                return false;
            }
            if(teacher.value == ‘‘) {
                alert(‘生产厂家为空‘);
                teacher.focus();
                return false;
            }
            if(teacher.value == ‘‘) {
                alert(‘入库日期为空‘);
                teacher.focus();
                return false;
            }
            if(classroom.value == ‘‘) {
                alert(‘型号为空‘);
                classroom.focus();
                return false;
            }
            if(date.value == ‘‘) {
                alert(‘型号为空‘);
                date.focus();
                return false;
            }
            if(size.value == ‘‘) {
                alert(‘型号为空‘);
                size.focus();
                return false;
            }
            if(amount.value == ‘‘) {
                alert(‘型号为空‘);
                amount.focus();
                return false;
            }
            if(out.value == ‘‘) {
                alert(‘型号为空‘);
                out.focus();
                return false;
            }
            if(give.value == ‘‘) {
                alert(‘型号为空‘);
                give.focus();
                return false;
            }
        }
    </script>
</body>
</html>

del.jsp

dao层

package com.hjf.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.hjf.entity.Course;
import com.hjf.util.DBUtil;

/**
 * 课程Dao
 * Dao层操作数据
 * @author Hu
 *
 */
public class CourseDao {

    /**
     * 添加
     * @param course
     * @return
     */
    public boolean add(Course course) {
        String sql = "insert into course(name, teacher, classroom,date,size,amount,out,give) values(‘" + course.getName() + "‘,‘" + course.getTeacher() + "‘,‘" + course.getClassroom()+"‘,‘"+course.getdate()+"‘," +course.getsize()+"‘,‘"+course.getamount()+"‘,‘"+course.getout()+"‘,‘"+course.getgive()+"‘,‘"+ "‘)";
        //创建数据库链接
        Connection conn = DBUtil.getConn();
        Statement state = null;
        boolean f = false;
        int a = 0;

        try {
            state = conn.createStatement();
            state.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭连接
            DBUtil.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public boolean delete (int id) {
        boolean f = false;
        String sql = "delete from course where id=‘" + id + "‘";

        Connection conn = DBUtil.getConn();
        Statement state = null;
        int a = 0;

        try {
            state = conn.createStatement();
            a = state.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }

    /**
     * 修改
     * @param name
     * @param pass
     */
    public boolean update(Course course) {
        String sql = "update course set name=‘" + course.getName() + "‘, teacher=‘" + course.getTeacher() + "‘, classroom=‘" + course.getClassroom()+"‘,date=‘"+course.getdate()+"‘,size=‘"+course.getsize()+"‘,amount=‘"+course.getamount()+"‘,out=‘"+course.getout()+"‘give=‘"+course.getgive()
            + "‘ where id=‘" + course.getId() + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        boolean f = false;
        int a = 0;

        try {
            state = conn.createStatement();
            a = state.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }

    /**
     * 验证课程名称是否唯一
     * true --- 不唯一
     * @param name
     * @return
     */
    public boolean name(String name) {
        boolean flag = false;
        String sql = "select name from course where name = ‘" + name + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }
        return flag;
    }

    /**
     * 通过ID得到课程信息
     * @param id
     * @return
     */
    public Course getCourseById(int id) {
        String sql = "select * from course where id =‘" + id + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;
        Course course = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                String name = rs.getString("name");
                String teacher = rs.getString("teacher");
                String classroom = rs.getString("classroom");
                String date=rs.getString("date");
                String size = rs.getString("size");
                String amount = rs.getString("amount");
                String out = rs.getString("out");
                String give = rs.getString("give");
                course = new Course( id,name, teacher, classroom,date,size,amount,out,give);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return course;
    }

    /**
     * 通过name得到Course
     * @param name
     * @return
     */
    public Course getCourseByName(String name) {
        String sql = "select * from course where name =‘" + name + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;
        Course course = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                int id = rs.getInt("id");
                String teacher = rs.getString("teacher");
                String classroom = rs.getString("classroom");
                String date=rs.getString("date");
                String size = rs.getString("size");
                String amount = rs.getString("amount");
                String out = rs.getString("out");
                String give = rs.getString("give");
                course = new Course(id, name, teacher, classroom,date,size,amount,out,give);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return course;
    }

    /**
     * 查找
     * @param name
     * @param teacher
     * @param classroom
     * @return
     */
    public List<Course> search(String name, String teacher, String classroom,String date,String size,String amount,String out,String give) {
        String sql = "select * from course where ";
        if (name != "") {
            sql += "name like ‘%" + name + "%‘";
        }
        if (teacher != "") {
            sql += "teacher like ‘%" + teacher + "%‘";
        }
        if (classroom != "") {
            sql += "classroom like ‘%" + classroom + "%‘";
        }
        if (date != "") {
            sql += "date like ‘%" + date + "%‘";
        }
        if (size != "") {
            sql += "size like ‘%" + size + "%‘";
        }

        if (amount != "") {
            sql += "amount like ‘%" + amount + "%‘";
        }
        if (out != "") {
            sql += "out like ‘%" + out + "%‘";
        }
        if (give != "") {
            sql += "give like ‘%" + give + "%‘";
        }
        List<Course> list = new ArrayList<>();
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            Course bean = null;
            while (rs.next()) {
                int id = rs.getInt("id");
                String name2 = rs.getString("name");
                String teacher2 = rs.getString("teacher");
                String classroom2 = rs.getString("classroom");
                String date2=rs.getString("date");
                String size2 = rs.getString("size");
                String amount2 = rs.getString("amount");
                String out2 = rs.getString("out");
                String give2 = rs.getString("give");
                bean = new Course(id, name2, teacher2, classroom2,date2,size2,amount2,out2,give2);
                list.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return list;
    }

    /**
     * 全部数据
     * @param name
     * @param teacher
     * @param classroom
     * @return
     */
    public List<Course> list() {
        String sql = "select * from course";
        List<Course> list = new ArrayList<>();
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            Course bean = null;
            while (rs.next()) {
                int id = rs.getInt("id");
                String name2 = rs.getString("name");
                String teacher2 = rs.getString("teacher");
                String classroom2 = rs.getString("classroom");
                String date2=rs.getString("date2");
                String size2 = rs.getString("size2");
                String amount2 = rs.getString("amount2");
                String out2 = rs.getString("out2");
                String give2 = rs.getString("give2");
                bean = new Course(id, name2, teacher2, classroom2,date2,size2,amount2,out2,give2);
                list.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return list;
    }

}

entity

package com.hjf.entity;

public class Course {

    private int id;
    private String name;
    private String teacher;
    private String classroom;
    private String date;//入库时间
    private String size;//规格
    private String amount;
    private String out;//出库时间
    private String give;//送货人姓名

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getdate() {
        return date;
    }
    public void setdate(String date) {
        this.date=date;
    }
    public String getsize() {
        return size;
    }
    public void setsize(String size) {
        this.size=size;
    }
    public String getamount() {
        return amount;
    }
    public void setamount(String amount) {
        this.amount=amount;
    }
    public String getout() {
        return out;
    }
    public void setout(String out) {
        this.out=out;
    }
    public String getgive() {
        return give;
    }
    public void setgive(String give) {
        this.give=give;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getTeacher() {
        return teacher;
    }
    public void setTeacher(String teacher) {
        this.teacher = teacher;
    }
    public String getClassroom() {
        return classroom;
    }
    public void setClassroom(String classroom) {
        this.classroom = classroom;
    }

    public Course() {}

    public Course(int id, String name, String teacher, String classroom,String date,String size,String amount,String out,String give) {
        this.id = id;
        this.name = name;
        this.teacher = teacher;
        this.classroom = classroom;
        this.date=date;
        this.size=size;
        this.amount=amount;
        this.out=out;
        this.give=give;
    }

    public Course(String name, String teacher, String classroom,String date,String size,String amount,String out,String give) {
        this.name = name;
        this.teacher = teacher;
        this.classroom = classroom;
        this.date=date;
        this.size=size;
        this.amount=amount;
        this.out=out;
        this.give=give;
    }
}

service

package com.hjf.service;

import java.util.List;

import com.hjf.dao.CourseDao;
import com.hjf.entity.Course;

/**
 * CourseService
 * 服务层
 * @author Hu
 *
 */
public class CourseService {

    CourseDao cDao = new CourseDao();

    /**
     * 添加
     * @param course
     * @return
     */
    public boolean add(Course course) {
        boolean f = false;
        if(!cDao.name(course.getName())) {
            cDao.add(course);
            f = true;
        }
        return f;
    }

    /**
     * 删除
     */
    public void del(int id) {
        cDao.delete(id);
    }

    /**
     * 修改
     * @return
     */
    public void update(Course course) {
        cDao.update(course);
    }

    /**
     * 通过ID得到一个Course
     * @return
     */
    public Course getCourseById(int id) {
        return cDao.getCourseById(id);
    }

    /**
     * 通过Name得到一个Course
     * @return
     */
    public Course getCourseByName(String name) {
        return cDao.getCourseByName(name);
    }

    /**
     * 查找
     * @return
     */
    public List<Course> search(String name, String teacher, String classroom,String date,String size,String amount,String out,String give) {
        return cDao.search(name, teacher, classroom,date,size,amount,out,give);
    }

    /**
     * 全部数据
     * @return
     */
    public List<Course> list() {
        return cDao.list();
    }
}

servlet

package com.hjf.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hjf.entity.Course;
import com.hjf.service.CourseService;

@WebServlet("/CourseServlet")
public class CourseServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    CourseService service = new CourseService();

    /**
     * 方法选择
     */
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String method = req.getParameter("method");

        if ("add".equals(method)) {
            add(req, resp);
        } else if ("del".equals(method)) {
            del(req, resp);
        } else if ("update".equals(method)) {
            update(req, resp);
        } else if ("search".equals(method)) {
            search(req, resp);
        } else if ("getcoursebyid".equals(method)) {
            getCourseById(req, resp);
        } else if ("getcoursebyname".equals(method)) {
            getCourseByName(req, resp);
        } else if ("list".equals(method)) {
            list(req, resp);
        }
    }

    /**
     * 添加
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        req.setCharacterEncoding("utf-8");
        //获取数据
        String name = req.getParameter("name");
        String teacher = req.getParameter("teacher");
        String classroom = req.getParameter("classroom");
        String date = req.getParameter("date");
        String size = req.getParameter("size");
        String amount = req.getParameter("amount");
        String out = req.getParameter("out");
        String give = req.getParameter("give");
        Course course = new Course(name, teacher, classroom,date,size,amount,out,give);

        //添加后消息显示
        if(service.add(course)) {
            req.setAttribute("message", "添加成功");
            req.getRequestDispatcher("add.jsp").forward(req,resp);
        } else {
            req.setAttribute("message", "商品名称重复,请重新录入");
            req.getRequestDispatcher("add.jsp").forward(req,resp);
        }
    }

    /**
     * 全部
     * @param req
     * @param resp
     * @throws ServletException
     */
    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");

        List<Course> courses = service.list();
        req.setAttribute("courses", courses);
        req.getRequestDispatcher("list.jsp").forward(req,resp);
    }

    /**
     * 通过ID得到Course
     * @param req
     * @param resp
     * @throws ServletException
     */
    private void getCourseById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        Course course = service.getCourseById(id);
        req.setAttribute("course", course);
        req.getRequestDispatcher("detail2.jsp").forward(req,resp);
    }

    /**
     * 通过名字查找
     * 跳转至删除
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void getCourseByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        Course course = service.getCourseByName(name);
        if(course == null) {
            req.setAttribute("message", "查无此物资!");
            req.getRequestDispatcher("del.jsp").forward(req,resp);
        } else {
            req.setAttribute("course", course);
            req.getRequestDispatcher("detail.jsp").forward(req,resp);
        }
    }

    /**
     * 删除
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        service.del(id);
        req.setAttribute("message", "删除成功!");
        req.getRequestDispatcher("del.jsp").forward(req,resp);
    }

    /**
     * 修改
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        String name = req.getParameter("name");
        String teacher = req.getParameter("teacher");
        String classroom = req.getParameter("classroom");
        String date = req.getParameter("date");
        String size = req.getParameter("size");
        String amount = req.getParameter("amount");
        String out = req.getParameter("out");
        String give = req.getParameter("give");
        Course course = new Course(id, name, teacher, classroom,date,size,amount,out,give);
        service.update(course);
        req.setAttribute("message", "修改成功");
        req.getRequestDispatcher("CourseServlet?method=list").forward(req,resp);
    }

    /**
     * 查找
     * @param req
     * @param resp
     * @throws ServletException
     */
    private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String teacher = req.getParameter("teacher");
        String classroom = req.getParameter("classroom");
        String date = req.getParameter("date");
        String size = req.getParameter("size");
        String amount = req.getParameter("amount");
        String out = req.getParameter("out");
        String give = req.getParameter("give");
        List<Course> courses = service.search(name, teacher, classroom,date,size,amount,out,give);
        req.setAttribute("courses", courses);
        req.getRequestDispatcher("searchlist.jsp").forward(req,resp);
    }
}

util

package com.hjf.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 数据库连接工具
 * @author Hu
 *
 */
public class DBUtil {

    public static String db_url = "jdbc:mysql://localhost:3306/course";
    public static String db_user = "root";
    public static String db_pass = "root";

    public static Connection getConn () {
        Connection conn = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");//加载驱动
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return conn;
    }

    /**
     * 关闭连接
     * @param state
     * @param conn
     */
    public static void close (Statement state, Connection conn) {
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close (ResultSet rs, Statement state, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws SQLException {
        Connection conn = getConn();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql ="select * from course";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        if(rs.next()){
            System.out.println("空");
        }else{
            System.out.println("不空");
        }
    }
}

add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
    <%
         Object message = request.getAttribute("message");
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">库存物资录入</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=add" method="post" onsubmit="return check()">
            <div class="a">
                物资名称<input type="text" id="name" name="name"/>
            </div>
            <div class="a">
                生产厂家<input type="text" id="teacher" name="teacher" />
            </div>
            <div class="a">
                型号<input type="text" id="classroom" name="classroom" />
            </div>
            <div class="a">
                入库日期<input type="text" id="date" name="date" />
                </div>
                <div class="a">
                规格<input type="text" id="size" name="size" />
                </div>
                <div class="a">
                数量<input type="text" id="amount" name="amount" />
                </div>
                <div class="a">
                送货人<input type="text" id="give" name="give" />
                </div>
                <div class="a">
                出库日期<input type="text" id="out" name="out" />
                </div>
            <div class="a">
                <button type="submit" class="b">保&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;存</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");;
            var teacher = document.getElementById("teacher");
            var classroom = document.getElementById("classroom");
            var date = document.getElementById("date");
            var size = document.getElementById("size");
            var amount = document.getElementById("amount");
            var out = document.getElementById("out");
            var give = document.getElementById("give");
            //非空
            if(name.value == ‘‘) {
                alert(‘物资名称为空‘);
                name.focus();
                return false;
            }
            if(teacher.value == ‘‘) {
                alert(‘生产厂家为空‘);
                teacher.focus();
                return false;
            }
            if(teacher.value == ‘‘) {
                alert(‘入库日期为空‘);
                teacher.focus();
                return false;
            }
            if(classroom.value == ‘‘) {
                alert(‘型号为空‘);
                classroom.focus();
                return false;
            }
            if(date.value == ‘‘) {
                alert(‘型号为空‘);
                date.focus();
                return false;
            }
            if(size.value == ‘‘) {
                alert(‘型号为空‘);
                size.focus();
                return false;
            }
            if(amount.value == ‘‘) {
                alert(‘型号为空‘);
                amount.focus();
                return false;
            }
            if(out.value == ‘‘) {
                alert(‘型号为空‘);
                out.focus();
                return false;
            }
            if(give.value == ‘‘) {
                alert(‘型号为空‘);
                give.focus();
                return false;
            }
        }
    </script>
</body>
</html>

del.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
    <%
         Object message = request.getAttribute("message");
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">物资信息删除</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=getcoursebyname" method="post" onsubmit="return check()">
            <div class="a">
                物资名称<input type="text" id="name" name="name"/>
            </div>
            <div class="a">
                <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;&nbsp;找</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");;

            //非空
            if(name.value == ‘‘) {
                alert(‘物资名称为空‘);
                name.focus();
                return false;
            }
        }
    </script>
</body>
</html>

detail.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
    .a{
        margin-top: 20px;
    }
    .b{
        font-size: 20px;
        width: 160px;
        color: white;
        background-color: greenyellow;
    }
    .tb, td {
        border: 1px solid black;
        font-size: 22px;
    }
</style>
</head>
<body>
    <div align="center">
        <h1 style="color: black;">物资信息删除</h1>
        <a href="index.jsp">返回主页</a>
        <table class="tb">
            <tr>
                <td>物资名称</td>
                <td>${course.name}</td>
            </tr>
            <tr>
                <td>生产厂家</td>
                <td>${course.teacher}</td>
            </tr>
            <tr>
                <td>型号</td>
                <td>${course.classroom}</td>
            </tr>
            <tr>
                <td>入库日期</td>
                <td>${course.date}</td>
            </tr>
            <tr>
                <td>规格</td>
                <td>${course.size}</td>
            </tr>
            <tr>
                <td>数量</td>
                <td>${course.amount}</td>
            </tr>
            <tr>
                <td>出库日期</td>
                <td>${course.out}</td>
            </tr>
            <tr>
                <td>送货人</td>
                <td>${course.give}</td>
            </tr>
        </table>
        <div class="a">
            <a onclick="return check()" href="CourseServlet?method=del&id=${course.id}">删&nbsp;&nbsp;&nbsp;&nbsp;除</a>
        </div>
    </div>
    <script type="text/javascript">
        function check() {
            if (confirm("真的要删除吗?")){
                return true;
            }else{
                return false;
            }
        }
    </script>
</body>
</html>

detail2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
    <%
         Object message = request.getAttribute("message");
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">物资信息修改</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=update" method="post" onsubmit="return check()">
            <div class="a">
                物资名称<input type="text" id="name" name="name" value="${course.name}"/>
            </div>
            <div class="a">
                生产厂家<input type="text" id="teacher" name="teacher" value="${course.teacher}"/>
            </div>
            <div class="a">
                型号<input type="text" id="classroom" name="classroom" value="${course.classroom}"/>
            </div>
            <div class="a">
                入库日期<input type="text" id="date" name="date" value="${course.date}"/>
            </div>
            <div class="a">
                规格<input type="text" id="size" name="size" value="${course.size}"/>
            </div>
            <div class="a">
                数量<input type="text" id="amount" name="amount" value="${course.amount}"/>
            </div>
            <div class="a">
                出库日期<input type="text" id="out" name="out" value="${course.out}"/>
            </div>
            <div class="a">
                送货人<input type="text" id="give" name="give" value="${course.give}"/>
            </div>
            <input type="hidden" id="id" name="id" value="${course.id}"/>
            <div class="a">
                <button type="submit" class="b">修&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;改</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");;
            var teacher = document.getElementById("teacher");
            var classroom = document.getElementById("classroom");
            var date = document.getElementById("date");
            var size = document.getElementById("size");
            var amount = document.getElementById("amount");
            var out = document.getElementById("out");
            var give = document.getElementById("give");
            //非空
            if(name.value == ‘‘) {
                alert(‘物资名称为空‘);
                name.focus();
                return false;
            }
            if(teacher.value == ‘‘) {
                alert(‘生产厂家为空‘);
                teacher.focus();
                return false;
            }
            if(classroom.value == ‘‘) {
                alert(‘型号为空‘);
                classroom.focus();
                return false;
            }
            if(date.value == ‘‘) {
                alert(‘入库日期为空‘);
                classroom.focus();
                return false;
            }
            if(size.value == ‘‘) {
                alert(‘规格为空‘);
                size.focus();
                return false;
            }
            if(amount.value == ‘‘) {
                alert(‘数量为空‘);
                amount.focus();
                return false;
            }
            if(out.value == ‘‘) {
                alert(‘出库日期为空‘);
                out.focus();
                return false;
            }
            if(give.value == ‘‘) {
                alert(‘送货人为空‘);
                give.focus();
                return false;
            }
        }
    </script>
</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>首页</title>

</head>
<body>
    <div align="center">

        <div class="a">
            <a href="add.jsp">库存物资添加</a>
        </div>
        <div class="a">
            <a href="CourseServlet?method=list">库存物资修改</a>
        </div>
        <div class="a">
            <a href="del.jsp">库存物资删除</a>
        </div>
        <div class="a">
            <a href="search.jsp">库存物资查询</a>
        </div>
    </div>
</body>
</html>

list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
    <%
         Object message = request.getAttribute("message");
         if(message!=null && !"".equals(message)){

    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: black;">物资信息列表</h1>
        <a href="index.jsp">返回主页</a>
        <table class="tb">
            <tr>
                <td>id</td>
                <td>物资名称</td>
                <td>生产厂家</td>
                <td>型号</td>
                <td>入库日期</td>
                <td>规格</td>
                <td>数量</td>
                <td>出库日期</td>
                <td>送货人</td>
                <td align="center" colspan="2">操作</td>
            </tr>
            <c:forEach items="${courses}" var="item">
                <tr>
                    <td>${item.id}</td>
                    <td>${item.name}</td>
                    <td>${item.teacher}</td>
                    <td>${item.classroom}</td>
                    <td>${item.date}</td>
                    <td>${item.size}</td>
                    <td>${item.amount}</td>
                    <td>${item.out}</td>
                    <td>${item.give}</td>
                    <td><a href="CourseServlet?method=getcoursebyid&id=${item.id}">修改</a></td>
                </tr>
            </c:forEach>
        </table>
    </div>
</body>
</html>

search.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
    <div align="center">
        <h1 style="color: black;">物资信息查询</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=search" method="post" onsubmit="return check()">
            <div class="a">
                物资名称<input type="text" id="name" name="name"/>
            </div>
            <div class="a">
                生产厂家<input type="text" id="teacher" name="teacher" />
            </div>
            <div class="a">
                型号<input type="text" id="classroom" name="classroom" />
            </div>
            <div class="a">
                入库日期<input type="text" id="date" name="date" />
            </div>
            <div class="a">
                规格<input type="text" id="size" name="size" />
                </div>
                <div class="a">
                数量<input type="text" id="amount" name="amount" />
                </div>
                <div class="a">
                送货人<input type="text" id="give" name="give" />
                </div>
                <div class="a">
                出库日期<input type="text" id="out" name="out" />
                </div>
            <div class="a">
                <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;询</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");
            var teacher = document.getElementById("teacher");
            var classroom = document.getElementById("classroom");
            var date = document.getElementById("date");
            var size = document.getElementById("size");
            var amount = document.getElementById("amount");
            var out = document.getElementById("out");
            var give = document.getElementById("give");
            //非空
            if(name.value == ‘‘ && teacher.value == ‘‘ && classroom.value == ‘‘&&date.value==‘‘&&size.value==‘‘&&amount.value==‘‘&&out.value==‘‘&&give.value==‘‘) {
                alert(‘请填写一个条件‘);
                return false;
            }
        }
    </script>
</body>
</html>

searchlist.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
    <div align="center">
        <h1 style="color: black;">物资信息列表</h1>
        <a href="index.jsp">返回主页</a>
        <table class="tb">
            <tr>
                <td>id</td>
                <td>物资名称</td>
                <td>生产厂家</td>
                <td>型号</td>
                <td>入库日期</td>
                <td>规格</td>
                <td>数量</td>
                <td>出库日期</td>
                <td>送货人</td>
            </tr>
            <!-- forEach遍历出adminBeans -->
            <c:forEach items="${courses}" var="item" varStatus="status">
                <tr>
                    <td>${item.id}</td>
                    <td><a>${item.name}</a></td>
                    <td>${item.teacher}</td>
                    <td>${item.classroom}</td>
                    <td>${item.date}</td>
                    <td>${item.size}</td>
                    <td>${item.amount}</td>
                    <td>${item.out}</td>
                    <td>${item.give}</td>
                </tr>
            </c:forEach>
        </table>
    </div>
</body>
</html>

原文地址:https://www.cnblogs.com/baixiaoli/p/10116954.html

时间: 2024-10-26 14:44:13

库存物资管理系统的相关文章

库存物资管理系统代码,详细过程和总结

库存物资管理系统实验要求如下: 1.背景资料 1.有一个存放商品的仓库,每天都有商品出库和入库.2.每种商品都有名称.生产厂家.型号.规格等.3.出入库时必须填写出入库单据,单据包括商品名称.生产厂家.型号.规格.数量.日期.时间.入库单位(或出库单位)名称.送货(或提货)人姓名.2.系统要求与功能设计2.1页面要求(1)能够在Tomcat服务器中正确部署,并通过浏览器查看:(1分)(2)网站页面整体风格统一:2.2设计要求1.设计出入库单据的录入.2.实现按商品名称.出入库日期的查询. 3.评

库存物资管理系统(过关测试)

实验要求: 1..有一个存放商品的仓库,每天都有商品出库和入库. 2.每种商品都有名称.生产厂家.型号.规格等. 3.出入库时必须填写出入库单据,单据包括商品名称.生产厂家.型号.规格.数量.日期.时间.入库单位(或出库单位)名称.送货(或提货)人姓名. 通过这次实验,我发现数据库的增删改查实验可以经由一个基本模板去演变,这样不但减少了工作量,同时使错误减少. 下面是此次测试的截图和代码 1 <%@ page language="java" import="java.u

库存物资管理系统-测试

实验要求: 1..有一个存放商品的仓库,每天都有商品出库和入库. 2.每种商品都有名称.生产厂家.型号.规格等. 3.出入库时必须填写出入库单据,单据包括商品名称.生产厂家.型号.规格.数量.日期.时间.入库单位(或出库单位)名称.送货(或提货)人姓名. 建两张数据表,一张用来商品的增删改查,一张记录商品的出库与入库信息 所用及代码: public class GoodsBean { private String name; private String type; private String

【javaweb】库存物资管理系统思路与总结

题目: 1.有一个存放商品的仓库,每天都有商品出库和入库. 2.每种商品都有名称.生产厂家.型号.规格等. 3.出入库时必须填写出入库单据,单据包括商品名称.生产厂家.型号. 规格.数量.日期.时间.入库单位(或出库单位)名称.送货(或提货)人 姓名. 首先建立数据库goodsmanager table:goods记录商品信息 table:list记录出入库信息 Java部分: 先把页面写好 首页面用<iframe>分为左侧导航栏,和右侧页面 点击左侧超链接即可实现右侧页面的跳转,在left.

疫情防控公益免费开源项目推荐-出入人员登记系统-学生健康报备管理系统-员工疫情筛查工具-物资管理系统-消毒检查登记系统

具体项目清单 项目1.出入人员登记系统 项目描述:疫情期间严格执行出入登记.支持出入人员自助扫码填表,支持管理员查看.统计.搜索和导出excel.还可根据车次.航班自动识别是否乘坐过确诊人员乘坐的交通工具.登记人员初次填写后,第二次填表将无需重复填写基本信息. 项目负责人:DCloud_UNI_GSQ(QQ群昵称) 项目体验地址:wlry.m3w.cn 源码地址:https://gitee.com/dcloud/xinguan2020-alien-registration 截图: 案例: 已经在

学习python两个月后,用了一个月用django写的物资管理系统

2017年5月,因为工作需要,单位急需一套物资管理系统来实现无纸化办公,当时也找外部门懂计算机编程的写过一套,用c(#)写的,因为是外单位做的,有很多细节无法满足工作需要,如果再进行改动,可能要重新做.求人不如靠自己,当时自己就有了一个想法,我要自己编写,或许只是一时的冲动,但如果做成了,确实能提升我在单位的自我价值.在此之前,我完全没有编程基础,只是在上中专的时候简单的学习过c语言,但那个时候已经是将近20年的事情了,编程在我脑子里完全没有概念.抱着试试看的态度,我决定开始学习.       

物资管理系统

一:首先连接数据库 package util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class JDBUtil { public static String url="jdbc:mysql://localhost:3306/test?u

基于bootstrap物资管理系统后台模板——后台

链接:http://pan.baidu.com/s/1geKwVMN 密码:0utl

关于物资管理系统

尽量学会去查找,定位到点,去解决问题,光看代码是没用的.比如,如何将web界面中的各个模块与代码对应上,这个是通过在数据库中输入相关的sql语句查询语句来查找的:而想要知道一个按键(或者组建什么的)是干嘛用的(用的什么方法),那就直接查询方法,对应到相关的方法,便可查看其用途. 无论web还是客户端,都有DataProcess文件,其中有三层架构,这些都是数据基础,每个程序只处理一个表格.而DataQuery中的Common和Common文件针对数据库是可以处理多个文件的. web端中的部分数据