• 仓库管理系统


    先说一下我的思路,创建两个数据库表,一个用来记录出库入库情况,另一个用来记录仓库中所有商品的信息,其中包括数量信息,再通过dao层,数据库连接层,Javabean,servlet,以及服务层service完成简单的对商品的增删改查,然后再出库的时候需要检查记录所有商品信息的数据表,检查能否出库,并且出库入库后,记录所有商品信息的数据表中的对应商品的数量也会随之发生改变。

    下面是代码:

    package connection;
    import java.sql.*;
    public class DBUtil {
    
    
        public static String db_url = "jdbc:mysql://localhost:3306/stu?useSSL=false";
        public static String db_user = "root";
        public static String db_pass = "123456";
        
        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;//返回了产生的Connection对象
        }
        
        /**
         * 关闭连接
         * @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();
                }
            }
        }
    
    }
    package dao;
    import connection.*;
    import sp.*;
    import xinxi.*;
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.List;
    public class daop {
    
        public static boolean add(xin x) {
            String s = String.valueOf(x.gete());
            String sql = "insert into ku(shangpin,changjia,xinghao,guige,shuliang,riqi,shijian,danwei,xingming,type) values('" + x.geta() + "','" + x.getb() + "','" + x.getc() + "','" + x.getd() +"','" + s +"','" + x.getf() +"','" + x.getg() +"','" + x.geth() +"','" + x.geti() + "','" + x.gettype() +"')";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            boolean f = false;
            int a = 0;
            
            try {
                state = conn.createStatement();
                a = state.executeUpdate(sql);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(state, conn);
            }
            
            if (a > 0) {
                f = true;
            }
            return f;
        }
        
        
        /*
         * 用商品名称查询
         */
        public static xin cha1(String name)
        {
            xin x=null;
            String sql = "select * from ku where shangpin ='" + name + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                while (rs.next()) {
                    String a = rs.getString("shangpin");
                    String b = rs.getString("changjia");
                    String c = rs.getString("xinghao");
                    String d = rs.getString("guige");
                    int e = rs.getInt("shuliang");
                    String f = rs.getString("riqi");
                    String g = rs.getString("shijian");
                    String h = rs.getString("danwei");
                    String i = rs.getString("xingming");
                    String type = rs.getString("type");
                    x=new xin(a,b,c,d,e,f,g,h,i,type);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            return x;
        }
        
        /*
         * 用出入库日期进行查询
         */
        public static xin cha2(String time)
        {
            xin x=null;
            String sql = "select * from ku where riqi ='" + time + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                while (rs.next()) {
                    String a = rs.getString("shangpin");
                    String b = rs.getString("changjia");
                    String c = rs.getString("xinghao");
                    String d = rs.getString("guige");
                    int e = rs.getInt("shuliang");
                    String f = rs.getString("riqi");
                    String g = rs.getString("shijian");
                    String h = rs.getString("danwei");
                    String i = rs.getString("xingming");
                    String type = rs.getString("type");
                    x=new xin(a,b,c,d,e,f,g,h,i,type);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            return x;
        }
        
        
        
        
        
        
        
        
        /*
         * 查询是否有商品
         */
        public static boolean name(String name) {
            boolean flag = false;
            String sql = "select shangpin from liang where shangpin = '" + 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;
        }
        /**
         * 添加
         * @param course
         * @return
         */
        public static boolean add(sp s) {
            String sql = "insert into liang(shangpin,changjia,xinghao,guige) values('" + s.getming() + "','" + s.getsheng() + "','" + s.getxing() + "','" + s.getgui() + "')";
            Connection conn = DBUtil.getConn();//创建connection对象,用来初始化statement对象
            Statement state = null;//创建statement对象,用来执行静态sql语句
            boolean f = false;
            int a = 0;
            try {
                state = conn.createStatement();//利用connection的creatstatement方法初始化statement对象
                a = state.executeUpdate(sql);//执行sql语句,并且返回执行sql语句成功的次数
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(state, conn);
            }
            
            if (a > 0) {
                f = true;
            }
            return f;
        }
        /**
         * 通过name得到Course
         * @param name
         * @return
         */
        public static sp findbyname(String name) {
            String sql = "select * from liang where shangpin ='" + name + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
            sp s = null;
            
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                while (rs.next()) {
                    String a = rs.getString("shangpin");
                    String b = rs.getString("changjia");
                    String c = rs.getString("xinghao");
                    String d = rs.getString("guige");
                    s=new sp(a,b,c,d);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            
            return s;
        }
        
        /*
         * 修改
         */
        public static boolean update(String name,sp s) {
            String sql = "update liang set shangpin='" + s.getming() + "', changjia='" + s.getsheng() + "', xinghao='" + s.getxing()+ "', guige='" +s.getgui()
                + "' where shangpin='" + name + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            boolean f = false;
            int a = 0;
    
            try {
                state = conn.createStatement();
                a = state.executeUpdate(sql);//执行sql语句,并返回执行成功sql语句条数
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(state, conn);
            }
            
            if (a > 0) {
                f = true;
            }
            return f;
        }
        
        /*
         * 删除
         */
        public static boolean delete (String name) {
            boolean f = false;
            String sql = "delete from liang where shangpin='" + name + "'";
            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;
        }
        
        /*
         * 模糊查询
         */
        public static List<sp> find(String a, String b, String c,String d) {
            String sql = "select * from classes where ";
            if (a != "") {
                sql += "shangpin like '%" + a + "%'";
            }
            if (b != "") {
                sql += "changjia like '%" + b + "%'";
            }
            if (c != "") {
                sql += "xinghao like '%" + c + "%'";
            }
            if (d != "") {
                sql += "guige like '%" + d + "%'";
            }
            List<sp> list = new ArrayList<>();
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
    
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                sp bean = null;
                while (rs.next()) {
                    String a1 = rs.getString("shangpin");
                    String b1 = rs.getString("changjia");
                    String c1 = rs.getString("xinghao");
                    String d1 = rs.getString("guige");
                    bean = new sp(a1,b1,c1,d1);
                    list.add(bean);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            
            return list;
        }
    }
    package ser;
    import dao.daop;
    import xinxi.xin;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    @WebServlet("/servlet")
    public class servlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
            req.setCharacterEncoding("utf-8");
            String method = req.getParameter("method");
            if ("chu".equals(method)) 
            {
                chu(req, resp);
            }
            else if("cha1".equals(method))
            {
                cha1(req,resp);
            }
            else if("ru".equals(method))
            {
                ru(req,resp);
            }
            else if("cha2".equals(method))
            {
                cha2(req,resp);
            }
        }
        private void chu(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
            req.setCharacterEncoding("utf-8");
            String a = req.getParameter("a");
            String b = req.getParameter("b");
            String c = req.getParameter("c");
            String d = req.getParameter("d");
            int e=Integer.valueOf(req.getParameter("e")).intValue();
            String f = req.getParameter("f");
            String g = req.getParameter("g");
            String h = req.getParameter("h");
            String i = req.getParameter("i");
            String type="出库";
            xin x=new xin(a,b,c,d,e,f,g,h,i,type);
            if(daop.name(a))
            {
                    daop.add(x);
                    req.setAttribute("message", "出库成功");
                    req.getRequestDispatcher("chu.jsp").forward(req,resp);
            }
            else
            {
                req.setAttribute("message", "未查询到该商品");
                req.getRequestDispatcher("chu.jsp").forward(req,resp);
            }
        }
        private void ru(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
            req.setCharacterEncoding("utf-8");
            String a = req.getParameter("a");
            String b = req.getParameter("b");
            String c = req.getParameter("c");
            String d = req.getParameter("d");
            int e=Integer.valueOf(req.getParameter("e")).intValue();
            String f = req.getParameter("f");
            String g = req.getParameter("g");
            String h = req.getParameter("h");
            String i = req.getParameter("i");
            String type="入库";
            xin x=new xin(a,b,c,d,e,f,g,h,i,type);
            if(daop.name(a))
            {
            daop.add(x);
            req.setAttribute("message", "入库成功");
            req.getRequestDispatcher("ru.jsp").forward(req,resp);
            }
            else
            {
                req.setAttribute("message", "未查询到该商品");
                req.getRequestDispatcher("ru.jsp").forward(req,resp);
            }
        }
        private void cha1(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    
            String name=req.getParameter("a");
            xin x=daop.cha1(name);
            if(x==null)
            {
                req.setAttribute("message", "未查询到该商品有出入库信息");
                req.getRequestDispatcher("shangpin.jsp").forward(req,resp);
            }
            else{
                req.setAttribute("x", x);
                req.getRequestDispatcher("show.jsp").forward(req,resp);
            }
        }
    
        /*
         * 
         */
        private void cha2(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    
            String time=req.getParameter("a");
            xin x=daop.cha1(time);
            if(x==null)
            {
                req.setAttribute("message", "未查询到该日期有商品出入库信息");
                req.getRequestDispatcher("riqi.jsp").forward(req,resp);
            }
            else
            {
                req.setAttribute("x", x);
                req.getRequestDispatcher("show.jsp").forward(req,resp);
            }
        }
    }
    package Service;
    import sp.*;
    import java.util.List;
    import dao.*;
    public class service {
    
        /*
         * 添加
         */
        public boolean add(sp s) {
            boolean f = false;
            if(!daop.name(s.getming())) {
                f=daop.add(s);
            }
            return f;
        }
        
        /*
         * 通过名字进行查找
         */
        public sp findbyname(String name) {
            return daop.findbyname(name);
        }
        
        
        /*
         * 修改
         */
        public boolean update(String name,sp s)
        {
            return daop.update(name,s);
        }
        
        /*
         * 删除
         */
        public void delete(String name)
        {
            daop.delete(name);
        }
        
        /*
         * 模糊查询
         */
        public List<sp> find(String a,String b,String c,String d)
        {
            return daop.find(a,b,c,d);
        }
    }
    package servlet;
    import Service.*;
    import java.io.IOException;
    import java.util.List;
    import sp.*;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    @WebServlet("/servlet1")
    public class servlet1 extends HttpServlet {
        private static final long serialVersionUID = 1L;
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // TODO Auto-generated method stub
            req.setCharacterEncoding("utf-8");
            String method = req.getParameter("method");
            if ("add".equals(method)) 
            {
                add(req, resp);
            }
            else if("findbynameupdate".equals(method))
            {
                findbynameupdate(req,resp);
            }
            else if("findbynamedelete".equals(method))
            {
                findbynamedelete(req,resp);
            }
            else if("update".equals(method))
            {
                update(req,resp);
            }
            else if("delete".equals(method))
            {
                delete(req,resp);
            }
            else if("find".equals(method))
            {
                find(req,resp);
            }
                
        }
        /*
         * 下面扩充几个方法
         */
    
        /**
         * 添加
         * @param req
         * @param resp
         * @throws IOException 
         * @throws ServletException 
         */
        private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
            req.setCharacterEncoding("utf-8");
            service Service=new service();
            String a = req.getParameter("a");
            String b = req.getParameter("b");
            String c = req.getParameter("c");
            String d = req.getParameter("d");
            sp s=new sp(a,b,c,d);
            
            //添加后消息显示
            if(Service.add(s)) {
                req.setAttribute("message", "添加成功");//setAttribute方法用于将内容保存在对象中,传到下一个页面中
                req.getRequestDispatcher("zs.jsp").forward(req,resp);//getRequestDispatcher方法用于进入下一个页面
            } else {
                req.setAttribute("message", "商品名称重复,请重新录入");
                req.getRequestDispatcher("zs.jsp").forward(req,resp);
            }
        }
        /**
         * 通过名字查找
         * @param req
         * @param resp
         * @throws IOException
         * @throws ServletException 
         */
        private void findbynameupdate(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            service Service=new service();
            String name = req.getParameter("name");
            sp s = Service.findbyname(name);
            if(s == null) {
                req.setAttribute("message", "查无此商品!");
                req.getRequestDispatcher("gs.jsp").forward(req,resp);
            } else {
                req.setAttribute("s", s);
                req.getRequestDispatcher("gs2.jsp").forward(req,resp);
            }
        }
        private void findbynamedelete(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            service Service=new service();
            String name = req.getParameter("name");
            sp s = Service.findbyname(name);
            if( s == null) {
                req.setAttribute("message", "查无此课程!");
                req.getRequestDispatcher("ss.jsp").forward(req,resp);
            } else {
                req.setAttribute("s", s);
                req.getRequestDispatcher("ss2.jsp").forward(req,resp);
            }
        }
        /*
         * 通过课程名称与新得到的课程进行修改课程信息
         */
        private void update(HttpServletRequest req, HttpServletResponse resp)throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            service Service=new service();
            String a = req.getParameter("a");
            String b = req.getParameter("b");
            String c = req.getParameter("c");
            String d = req.getParameter("d");
            String name1=req.getParameter("name1");
            sp s=new sp(a,b,c,d);
            if(Service.update(name1, s)){
            req.setAttribute("message", "课程信息修改成功");
            req.getRequestDispatcher("gs.jsp").forward(req,resp);
            }
            else{
                req.setAttribute("message", "课程信息修改失败");
                req.getRequestDispatcher("gs.jsp").forward(req,resp);
            }
        }
        
        /*
         * 通过课程名称删除课程信息
         */
        private void delete(HttpServletRequest req, HttpServletResponse resp)throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            service Service=new service();
            String name = req.getParameter("name");
            Service.delete(name);
            req.setAttribute("message", "课程信息删除成功");
            req.getRequestDispatcher("ss.jsp").forward(req,resp);
        }
    
        /*
         * 模糊查找
         */
        private void find(HttpServletRequest req, HttpServletResponse resp)throws IOException, ServletException{
            
            req.setCharacterEncoding("utf-8");
            service Service=new service();
            String a = req.getParameter("a");
            String b = req.getParameter("b");
            String c = req.getParameter("c");
            String d = req.getParameter("d");
            List<sp> courses = Service.find(a,b,c,d);
            req.setAttribute("courses", courses);
            req.getRequestDispatcher("cs2.jsp").forward(req,resp);
        }
    
    }
    package sp;
    
    public class sp {
    
        String ming;
        String sheng;
        String xing;
        String gui;
        public String getming()
        {
            return ming;
        }
        public String getsheng()
        {
            return sheng;
        }
        public String getxing()
        {
            return xing;
        }
        public String getgui()
        {
            return gui;
        }
        public sp(String a,String b,String c,String d)
        {
            ming=a;
            sheng=b;
            xing=c;
            gui=d;
        }
    }
    package xinxi;
    
    public class xin {
    
        String a;
        String b;
        String c;
        String d;
        int e;
        String f;
        String g;
        String h;
        String i;
        String type;
        public xin(int e)
        {
            this.e=e;
        }
        public String geta()
        {
            return a;
        }
        public String getb()
        {
            return b;
        }
        public String getc()
        {
            return c;
        }
        public String getd()
        {
            return d;
        }
        public int gete()
        {
            return e;
        }
        public String getf()
        {
            return f;
        }
        public String getg()
        {
            return g;
        }
        public String geth()
        {
            return h;
        }
        public String geti()
        {
            return i;
        }
        public String gettype()
        {
            return type;
        }
        public xin(String a,String b,String c,String d,int e,String f,String g,String h,String i,String type)
        {
            this.a=a;
            this.b=b;
            this.c=c;
            this.d=d;
            this.e=e;
            this.f=f;
            this.g=g;
            this.h=h;
            this.i=i;
            this.type=type;
        }
        
    }
    <%@ 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>Insert title here</title>
    </head>
    <body>
    <h2>请选择查询方式</h2>
    <a href=shangpin.jsp>按照商品名称查询</a>
    <a href=riqi.jsp>按照出入库日期查询</a>
    </body>
    </html>
    <%@ 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>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: red;">出库单据</h1>
            <a href="main.jsp">返回主页</a>
            <form action="servlet?method=chu" method="post">
                                                                                                    
                <div class="a">
                    商品<input type="text" name="a"/>             
                </div>
                <div class="a">
                    厂家<input type="text" name="b" />
                </div>
                <div class="a">
                    型号<input type="text" name="c" />
                </div>
                <div class="a">
                    规格<input type="text" name="d" />
                </div>
                <div class="a">
                    数量<input type="text" name="e" />
                </div>
                <div class="a">
                    日期<input type="text" name="f" />
                </div>
                <div class="a">
                    时间<input type="text" name="g" />
                </div>
                <div class="a">
                    单位<input type="text" name="h" />
                </div>
                <div class="a">
                    姓名<input type="text" name="i" />
                </div>
                <div class="a">
                    <button type="submit" class="b">保&nbsp;&nbsp;&nbsp;存</button>
                </div>
            </form>
        </div>
    </body>
    </html>
    <%@ 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>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: red;">课程信息查询</h1>
            <a href="main.jsp">返回主页</a>
            <form action="stuservlet?method=find" method="post" >
                                                                                                    
                <div class="a">
                    商品名称<input type="text"  name="a"/>             
                </div>
                <div class="a">
                    生产厂家<input type="text"  name="b" />
                </div>
                <div class="a">
                    型号<input type="text"  name="c" />
                </div>
                <div class="a">
                    规格<input type="text"  name="d" />
                </div>
                <div class="a">
                    <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;询</button>
                </div>
            </form>
        </div>
    </body>
    </html>
    <%@ 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>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>
    <%} %>
        <h2>修改商品信息</h2>
    <form action="servlet1?method=findbynameupdate" method="post" onsubmit="return check()">
    <a href="main.jsp">返回主页</a>
    <div class="a">
        商品名称<input type="text" id="name" name="name"/>             
    </div>
    <div class="a">
        <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;询</button>
    </div>
    </form>
    <script type="text/javascript">
            function check() {
                var name = document.getElementById("name");;
                //非空
                if(name.value == '') {
                    alert('请输入数据');
                    name.focus();//focus()方法是将输入焦点移至对象上
                    return false;
                }
            }
    </script>
    </body>
    <%@ 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>Insert title here</title>
    </head>
    <body>
    <h3>原商品信息</h3>
    <form>
    商品名称: ${s.ming}<br>
    生产厂家:${s.sheng}<br>
    型号:${s.xing}<br>
    规格:${s.gui}<br>
    </form>
    <h3>请输入新的商品信息进行修改</h3>
    <form action="servlet1?method=update&name1=${s.ming}" method="post" onsubmit="return check()">
                                                                                                    
                <div class="a">
                    商品名称<input type="text" id="name" name="a"/>             
                </div>
                <div class="a">
                    生产厂家<input type="text" id="changjia" name="b" />
                </div>
                <div class="a">
                    型号<input type="text" id="classroom" name="c" />
                </div>
                <div class="a">
                    规格<input type="text" id="classroom1" name="d" />
                </div>
                <div class="a">
                    <button type="submit" class="b">修&nbsp;&nbsp;&nbsp;改</button>
                </div>
    </form>
    <script type="text/javascript">
            function check() {
                var name = document.getElementById("name");;
                var teacher = document.getElementById("teacher");
                var classroom = document.getElementById("classroom");//document.getElementById("")用于通过id获取表单中客户输入的值
                var classroom1 = document.getElementById("classroom1")
                //非空
                if(name.value == '') {
                    alert('商品名称为空');
                    name.focus();//focus()方法是将输入焦点移至对象上
                    return false;
                }
                if(teacher.value == '') {
                    alert('生产厂家为空');
                    teacher.focus();
                    return false;
                }
                if(classroom.value == '') {
                    alert('型号为空');
                    classroom.focus();
                    return false;
                }
                if(classroom1.value == '') {
                    alert('规格为空');
                    classroom.focus();
                    return false;
                }
            }
        </script>
    </body>
    </html>
    <%@ 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>Insert title here</title>
    </head>
    <body>
    <h2>请选择出库,入库或查询记录</h2>
    <a href=zs.jsp>增加商品</a><br>
    <a href=ss.jsp>删除商品</a><br>
    <a href=cs.jsp>查询商品</a><br>
    <a href=xs.jsp>修改商品</a><br>
    <a href=chu.jsp>出库</a><br>
    <a href=ru.jsp>入库</a><br>
    <a href=cha.jsp>查询出库入库信息</a><br>
    </body>
    </html>
    <%@ 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>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>
    <%} %>
    <h2>请输入出入库日期进行查询</h2>
    <form action="servlet?method=cha2" method="post" >
                                                                                                    
                <div class="a">
                    日期:<input type="text" name="a"/>             
                </div>
                <div class="a">
                    <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;询</button>
                </div>
    </form>
    </body>
    </html>
    <%@ 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>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: red;">入库单据</h1>
            <a href="main.jsp">返回主页</a>
            <form action="servlet?method=chu" method="post" onsubmit="return check()">
                                                                                                    
                <div class="a">
                    商品<input type="text" name="a"/>             
                </div>
                <div class="a">
                    厂家<input type="text" name="b" />
                </div>
                <div class="a">
                    型号<input type="text" name="c" />
                </div>
                <div class="a">
                    规格<input type="text" name="d" />
                </div>
                <div class="a">
                    数量<input type="text" name="e" />
                </div>
                <div class="a">
                    日期<input type="text" name="f" />
                </div>
                <div class="a">
                    时间<input type="text" name="g" />
                </div>
                <div class="a">
                    单位<input type="text" name="h" />
                </div>
                <div class="a">
                    姓名<input type="text" name="i" />
                </div>
                <div class="a">
                    <button type="submit" class="b">保&nbsp;&nbsp;&nbsp;存</button>
                </div>
            </form>
        </div>
    </body>
    </html>
    <%@ 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>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>
    <%} %>
    <h2>请输入商品名称进行查询</h2>
    <form action="servlet?method=cha1" method="post">
                                                                                                    
                <div class="a">
                    商品名称:<input type="text" name="a"/>             
                </div>
                <div class="a">
                    <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;询</button>
                </div>
    </form>
    </body>
    </html>
    <%@ 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>Insert title here</title>
    </head>
    <body>
    <h3>出入库信息</h3>
    <form>
    商品:${x.a}<br>
    厂家:${x.b}<br>
    型号:${x.c}<br>
    规格:${x.d}<br>
    数量:${x.e}<br>
    日期:${x.f}<br>
    时间:${x.g}<br>
    单位:${x.h}<br>
    姓名:${x.i}<br>
    出库与入库:${x.type}<br>
    </form>
    </body>
    </html>
    <%@ 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>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>
    <%} %>
    <h2>请输入课程名称进行删除</h2>
    <form action="servlet1?method=findbynamedelete" method="post" onsubmit="return check()">
    <a href="main.jsp">返回主页</a>
    <div class="a">
        商品名称<input type="text" id="name" name="name"/>             
    </div>
    <div class="a">
        <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;询</button>
    </div>
    </form>
    <script type="text/javascript">
            function check() {
                var name = document.getElementById("name");;
                //非空
                if(name.value == '') {
                    alert('请输入数据');
                    name.focus();//focus()方法是将输入焦点移至对象上
                    return false;
                }
            }
    </script>
    </body>
    </html>
    <%@ 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>Insert title here</title>
    </head>
    <body>
    <h3>原商品信息</h3>
    <form>
    商品名称: ${s.ming}<br>
    生产厂家:${s.sheng}<br>
    型号:${s.xing}<br>
    规格:${s.gui}<br>
    </form>
    <a onclick="return check()" href="servlet1?method=delete&name=${s.ming}">删&nbsp;&nbsp;&nbsp;除</a>
    <script type="text/javascript">
            function check() {
                if (confirm("真的要删除吗?")){
                    return true;
                }else{
                    return false;
                }
            }
        </script>
    </body>
    </html>
    <%@ 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>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: red;">商品信息录入</h1>
            <a href="main.jsp">返回主页</a>
            <form action="servlet1?method=add" method="post">                                                                                
                <div class="a">
                    名称<input type="text" name="a"/>             
                </div>
                <div class="a">
                    厂家<input type="text" name="b" />
                </div>
                <div class="a">
                    型号<input type="text" name="c" />
                </div>
                <div class="a">
                    规格<input type="text" name="d" />
                </div>
                <div class="a">
                    <button type="submit" class="b">保&nbsp;&nbsp;&nbsp;存</button>
                </div>
            </form>
        </div>
    </body>
    </html>

    代码原创,还有很多地方需要完善

  • 相关阅读:
    Java FileInputStream与FileReader的区别
    java 保存和读取本地json文件
    java写文件时往末尾追加文件(而不是覆盖原文件),的两种方法总结
    Java魔法堂:注解用法详解——@SuppressWarnings
    使用Restlet Client发送各种Get和Post请求
    postman VS restlet client基本使用
    Java获取请求客户端的真实IP地址
    dom4j解析xml字符串实例
    C++ Boost库简介(一些自己的感受)
    打仗其实最讲成本核算,大炮轰的都是黄金,日军在中国就是不断赔本
  • 原文地址:https://www.cnblogs.com/123456www/p/10117277.html
Copyright © 2020-2023  润新知