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

CourseDao.java

对数据库的操作,实现增删改查

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; public class CourseDao { public boolean add(Course course) {
String sql = "insert into course(name, changjia, xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo)"
+ " values('" + course.getName() + "','" + course.getChangjia() + "','" + course.getXinghao() + "','" +course.getGuige() +"','" + course.getShuliang()+ "','" +course.getRiqi()+ "','" +course.getShijian()+ "','" +course.getRuku()+ "','" +course.getChuku()+ "','" +course.getSonghuo()+ "','" +course.getTihuo()+"')";
//sql=" insert into course(name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo) values ('8','8','8','8','8','8','8','8','8','8','8')";
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;
} 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;
} public boolean update(Course course) {
String sql = "update course set name='" + course.getName() + "', changjia='" + course.getChangjia() + "', xinghao='" + course.getXinghao()+ "', guige='" + course.getGuige()+ "',shuliang='" + course.getShuliang()+ "', riqi='" + course.getRiqi()+ "',shijian='" + course.getShijian()+ "', ruku='" + course.getRuku()+ "', chuku='" + course.getChuku()+ "',songhuo='" + course.getSonghuo()+ "', tihuo='" + course.getTihuo()
+ "' 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;
} 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;
} 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 changjia = rs.getString("changjia");
String xinghao = rs.getString("xinghao");
String guige = rs.getString("guige");
String shuliang = rs.getString("shuliang");
String riqi = rs.getString("riqi");
String shijian = rs.getString("shijian");
String ruku = rs.getString("ruku");
String chuku = rs.getString("chuku");
String songhuo = rs.getString("songhuo");
String tihuo = rs.getString("tihuo");
course = new Course(id, name, changjia, xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
} return course;
} 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 name1 = rs.getString("name");
String changjia = rs.getString("changjia");
String xinghao = rs.getString("xinghao");
String guige = rs.getString("guige");
String shuliang = rs.getString("shuliang");
String riqi = rs.getString("riqi");
String shijian = rs.getString("shijian");
String ruku = rs.getString("ruku");
String chuku = rs.getString("chuku");
String songhuo = rs.getString("songhuo");
String tihuo = rs.getString("tihuo");
course = new Course(id, name1,changjia, xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
} return course;
} public List<Course> search(String name, String changjia, String xinghao,String guige,String shuliang,String riqi,String shijian,String ruku,String chuku,String songhuo,String tihuo) {
String sql = "select * from course where ";
if (name != "" &&name != null) {
sql += "name like '%" + name + "%'";
}
if (changjia != ""&&changjia !=null) {
sql += "changjia like '%" + changjia + "%'";
}
if (xinghao != ""&&xinghao!=null) {
sql += "xinghao like '%" + xinghao + "%'";
}
if (guige != ""&&guige!=null) {
sql += "guige like '%" + guige + "%'";
}
if (shuliang != ""&&shuliang!=null) {
sql += "shuliang like '%" + shuliang + "%'";
}
if (riqi != ""&&riqi!=null) {
sql += "riqi like '%" + riqi + "%'";
}
if (shijian != ""&&shijian!=null) {
sql += "shijian like '%" + shijian + "%'";
}
if (ruku != ""&&ruku!=null) {
sql += "ruku like '%" + ruku + "%'";
}
if (chuku != ""&&chuku!=null) {
sql += "chuku like '%" + chuku + "%'";
}
if (songhuo != ""&&songhuo!=null) {
sql += "songhuo like '%" + songhuo + "%'";
}
if (tihuo!= ""&&tihuo!=null) {
sql += "tihuo like '%" + tihuo + "%'";
}
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 changjia2 = rs.getString("changjia");
String xinghao2 = rs.getString("xinghao");
String guige2 = rs.getString("guige");
String shuliang2 = rs.getString("shuliang");
String riqi2 = rs.getString("riqi");
String shijian2 = rs.getString("shijian");
String ruku2 = rs.getString("ruku");
String chuku2 = rs.getString("chuku");
String songhuo2 = rs.getString("songhuo");
String tihuo2 = rs.getString("tihuo");
bean = new Course(id, name2, changjia2,xinghao2,guige2,shuliang2,riqi2,shijian2,ruku2,chuku2,songhuo2,tihuo2);
System.out.println(bean.getName());
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
} return list;
} 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 changjia2 = rs.getString("changjia");
String xinghao2 = rs.getString("xinghao");
String guige2 = rs.getString("guige");
String shuliang2 = rs.getString("shuliang");
String riqi2 = rs.getString("riqi");
String shijian2 = rs.getString("shijian");
String ruku2 = rs.getString("ruku");
String chuku2 = rs.getString("chuku");
String songhuo2 = rs.getString("songhuo");
String tihuo2 = rs.getString("tihuo");
bean = new Course(id, name2, changjia2,xinghao2,guige2,shuliang2,riqi2,shijian2,ruku2,chuku2,songhuo2,tihuo2);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
} return list;
} }

对于数据的封装

Course.java

package com.hjf.entity;

public class Course {

    private int id;
private String name;
private String changjia;
private String xinghao;
private String guige;
private String shuliang;
private String riqi;
private String shijian;
private String ruku;
private String chuku;
private String songhuo;
private String tihuo; public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getChangjia() {
return changjia;
}
public void setChangjia(String changjia) {
this.changjia = changjia;
}
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
public String getGuige() {
return guige;
}
public void setGuige(String guige) {
this.guige = guige;
}
public String getShuliang() {
return shuliang;
}
public void setShuliang(String shuliang) {
this.shuliang = shuliang;
}
public String getRiqi() {
return riqi;
}
public void setRiqi(String riqi) {
this.riqi = riqi;
}
public String getShijian() {
return shijian;
}
public void setShijian(String shijian) {
this.shijian = shijian;
}
public String getRuku() {
return ruku;
}
public void setRuku(String ruku) {
this.ruku = ruku;
}
public String getChuku() {
return chuku;
}
public void setChuku(String chuku) {
this.chuku = chuku;
}
public String getSonghuo() {
return songhuo;
}
public void setSonghuo(String songhuo) {
this.songhuo = songhuo;
}
public String getTihuo() {
return tihuo;
}
public void setTihuo(String tihuo) {
this.tihuo = tihuo;
}
public Course() {} public Course(int id, String name, String changjia, String xinghao, String guige, String shuliang, String riqi, String shijian, String ruku, String chuku, String songhuo, String tihuo) {
this.id = id;
this.name = name;
this.changjia = changjia;
this.xinghao = xinghao;
this.guige = guige;
this.shuliang = shuliang;
this.riqi = riqi;
this.shijian = shijian;
this.ruku = ruku;
this.chuku = chuku;
this.songhuo = songhuo;
this.tihuo = tihuo;
} public Course(String name, String changjia, String xinghao, String guige, String shuliang, String riqi, String shijian, String ruku, String chuku, String songhuo, String tihuo) {
this.name = name;
this.changjia = changjia;
this.xinghao = xinghao;
this.guige = guige;
this.shuliang = shuliang;
this.riqi = riqi;
this.shijian = shijian;
this.ruku = ruku;
this.chuku = chuku;
this.songhuo = songhuo;
this.tihuo = tihuo;
}
}

Course.java

数据的集合

CourseService.java

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);
} /** * @return
*/
public Course getCourseById(int id) {
return cDao.getCourseById(id);
} /** * @return
*/
public Course getCourseByName(String name) {
return cDao.getCourseByName(name);
} /**
* @return
*/
public List<Course> search(String name,String changjia, String xinghao, String guige, String shuliang, String riqi, String shijian, String ruku, String chuku, String songhuo, String tihuo) {
return cDao.search(name, changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo);
} public List<Course> list() {
return cDao.list();
}
}

CourseService.java

连接数据库,实现增删改查

CourseServlet.java

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 changjia = req.getParameter("changjia");
String xinghao = req.getParameter("xinghao");
String guige = req.getParameter("guige");
String shuliang = req.getParameter("shuliang");
String riqi = req.getParameter("riqi");
String shijian = req.getParameter("shijian");
String ruku = req.getParameter("ruku");
String chuku = req.getParameter("chuku");
String songhuo = req.getParameter("songhuo");
String tihuo = req.getParameter("tihuo");
Course course = new Course(name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); 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);
} /*
* @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 changjia = req.getParameter("changjia");
String xinghao = req.getParameter("xinghao");
String guige = req.getParameter("guige");
String shuliang = req.getParameter("shuliang");
String riqi = req.getParameter("riqi");
String shijian = req.getParameter("shijian");
String ruku = req.getParameter("ruku");
String chuku = req.getParameter("chuku");
String songhuo = req.getParameter("songhuo");
String tihuo = req.getParameter("tihuo");
Course course = new Course(id, name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); 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 changjia = req.getParameter("changjia");
String xinghao = req.getParameter("xinghao");
String guige = req.getParameter("guige");
String shuliang = req.getParameter("shuliang");
String riqi = req.getParameter("riqi");
String shijian = req.getParameter("shijian");
String ruku = req.getParameter("ruku");
String chuku = req.getParameter("chuku");
String songhuo = req.getParameter("songhuo");
String tihuo = req.getParameter("tihuo");
List<Course> courses = service.search(name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo);
req.setAttribute("courses", courses);
req.getRequestDispatcher("searchlist.jsp").forward(req,resp);
}
}

index.jsp

主界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>首页</title>
<style>
.a{
font-size: 26px;
margin-top: 20px;
}
</style>
</head>
<body>
<div align="center">
<h1 style="color: red;">库存物资管理系统</h1>
<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>

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>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: pink;
background-color: yellow;
}
</style>
</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>
<h1 style="color: red;">入库单据</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="changjia" name="changjia" />
</div>
<div class="a">
型号<input type="text" id="xinghao" name="xinghao" />
</div>
<div class="a">
规格<input type="text" id="guige" name="guige" />
</div>
<div class="a">
数量<input type="text" id="shuliang" name="shuliang" />
</div>
<div class="a">
日期<input type="text" id="riqi" name="riqi" />
</div>
<div class="a">
时间<input type="text" id="shijian" name="shijian" />
</div>
<div class="a">
入库单位名称<input type="text" id="ruku" name="ruku" />
</div>
<div class="a">
送货人姓名<input type="text" id="songhuo" name="songhuo" />
</div>
<div class="a">
<button type="submit" class="b">保&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;存</button>
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var name = document.getElementById("name");;
var changjia = document.getElementById("changjia");
var xinghao = document.getElementById("xinghao");
var guige = document.getElementById("guige");
var shuliang = document.getElementById("shuliang");
var riqi = document.getElementById("riqi");
var shijian = document.getElementById("shijian");
var ruku = document.getElementById("ruku");
var songhuo = document.getElementById("songhuo"); //非空
if(name.value == '') {
alert('商品名称为空');
name.focus();
return false;
}
if(changjia.value == '') {
alert('生产厂家为空');
changjia.focus();
return false;
}
if(xinghao.value == '') {
alert('型号为空');
xinghao.focus();
return false;
}
if(guige.value == '') {
alert('规格为空');
guige.focus();
return false;
}
if(shuliang.value == '') {
alert('数量为空');
shuliang.focus();
return false;
}
if(riqi.value == '') {
alert('日期为空');
riqi.focus();
return false;
}
if(shijian.value == '') {
alert('时间为空');
shijian.focus();
return false;
}
if(ruku.value == '') {
alert('入库单位名称为空');
ruku.focus();
return false;
} if(songhuo.value == '') {
alert('送货人姓名为空');
songhuo.focus();
return false;
} }
</script>
</body>
</html>

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>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: pink;
background-color: yellow;
}
</style>
</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="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;找</button>
</div>
</form> <script type="text/javascript">
function check() {
var name = document.getElementById("name");; //非空
if(name.value == '') {
alert('无此商品');
name.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>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: pink;
background-color: yellow;
}
.tb, td {
border: 1px solid black;
font-size: 22px;
}
</style>
</head>
<body>
<div align="center">
<h1 style="color: red;">商品出库</h1>
<a href="index.jsp">返回主页</a>
<table class="tb">
<tr>
<td>商品名称</td>
<td>${course.name}</td>
</tr>
<tr>
<td>生产厂家</td>
<td>${course.changjia}</td>
</tr>
<tr>
<td>型号</td>
<td>${course.xinghao}</td>
</tr>
<tr>
<td>规格</td>
<td>${course.guige}</td>
</tr>
<div align="center"> <div align="center">
</div>
<h1 style="color: red;">出库单据</h1>
<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="changjia" name="changjia" />
</div>
<div class="a">
型号<input type="text" id="xinghao" name="xinghao" />
</div>
<div class="a">
规格<input type="text" id="guige" name="guige" />
</div>
<div class="a">
数量<input type="text" id="shuliang" name="shuliang" />
</div>
<div class="a">
日期<input type="text" id="riqi" name="riqi" />
</div>
<div class="a">
时间<input type="text" id="shijian" name="shijian" />
</div>
<div class="a">
出库单位名称<input type="text" id="chuku" name="chuku" />
</div>
<div class="a">
提货人姓名<input type="text" id="tihuo" name="tihuo" />
</div>
<div class="a">
<button type="submit" class="b">保&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;存</button>
</div> </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>

detail.jsp

商品出库

输入出单库据及删除商品

如果无此商品

商品修改,可以进行单个信息的修改

界面一list.jsp 在界面一可以看到所有信息并进行修改,转到界面二

界面二detail2.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>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: pink;
background-color:yellow;
}
.tb, td {
border: 1px solid black;
font-size: 22px;
}
</style>
</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="index.jsp">返回主页</a>
<table class="tb">
<tr>
<td>id</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.changjia}</td>
<td>${item.xinghao}</td>
<td>${item.guige}</td>
<td><a href="CourseServlet?method=getcoursebyid&id=${item.id}">修改</a></td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>

list.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: pink;
background-color: yellow;
}
</style>
</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="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="changjia" name="changjia" value="${course.changjia}"/>
</div>
<div class="a">
型号<input type="text" id="xinghao" name="xinghao" value="${course.xinghao}"/>
</div>
<div class="a">
规格<input type="text" id="guige" name="guige" value="${course.guige}"/>
</div>
<input type="hidden" id="id" name="id" value="${course.id}"/>
<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");;
var changjia= document.getElementById("changjia");
var xinghao = document.getElementById("xinghao");
var guige = document.getElementById("guige"); //非空
if(name.value == '') {
alert('商品名称为空');
name.focus();
return false;
}
if(changjia.value == '') {
alert('生产厂家为空');
changjia.focus();
return false;
}
if(xinghao.value == '') {
alert('规格为空');
xinghao.focus();
return false;
}
if(guige.value == '') {
alert('规格为空');
guige.focus();
return false;
} }
</script>
</body>
</html>

detail2.jsp

查询商品信息,可以做到模糊查询

界面一search.jsp进行关键字模糊查询

界面二searchlist.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: pink;
background-color: yellow;
}
</style>
</head>
<body>
<div align="center">
<h1 style="color: red;">商品信息查询</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">
<button type="submit" class="b">查&nbsp;询</button>
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var name = document.getElementById("name");;
var changjia = document.getElementById("changjia");
var xinghao = document.getElementById("xinghao");
var guige = document.getElementById("guige");
var shuliang = document.getElementById("shuliang");
var riqi = document.getElementById("riqi");
var shijian = document.getElementById("shijian");
var ruku = document.getElementById("ruku");
var chuku = document.getElementById("chuku");
var songhuo = document.getElementById("songhuo");
var quhuo = document.getElementById("quhuo"); //非空
if(name.value == '' && changjia.value == '' && xinghao.value == '' && guige.value == ''&& shuliang.value == ''&& riqi.value == ''&& shijian.value == ''&& ruhuo.value == ''&& chuhuo.value == ''&& songhuo.value == ''&& tihuo.value == '') {
alert('请填写一个条件');
return false;
}
}
</script>
</body>
</html>

search.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>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: pink;
background-color: yellow;
}
.tb, td {
border: 1px solid black;
font-size: 22px;
}
</style>
</head>
<body>
<div align="center">
<h1 style="color: red;">商品信息列表</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>出库单位名称</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.changjia}</td>
<td>${item.xinghao}</td>
<td>${item.guige}</td>
<td>${item.shuliang}</td>
<td>${item.riqi}</td>
<td>${item.shijian}</td>
<td>${item.ruku}</td>
<td>${item.chuku}</td>
<td>${item.songhuo}</td>
<td>${item.tihuo}</td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>

searchlist.java

ps:所有的返回主页均可直接返回主页面

Java过关测验的更多相关文章

  1. java第一次测验

    package kaoshi; import java.util.Scanner; public class ScoreManagement { static int t=0; static int ...

  2. 2019.9.16:java课后测验

    一.动手动脑 1. 枚举类型是引用类型, 枚举不属于原始数据类型,它的每个具体值都引用一个特定的对象.相同的值则引用同一个对象. 可以使用“==”和equals()方法直接比对枚举变量的值,换句话说, ...

  3. 八成Java开发者解答不了的问题

    统计数据来自Java“死亡”竞赛——一个针对开发者的迷你测验 几个月前,我们在一个小型网站上发布了一个称为Java“死亡竞赛”的新项目.测验发布后,超过20000位开发者参加了测验.网站以20道关于J ...

  4. Java基础知识强化14:Java死亡竞赛题目解析

      一个小型网站上发布了一个称为Java“死亡竞赛”的新项目.测验发布后,超过20000位开发者参加了测验.网站以20道关于Java的多选题为主.我们得到了众多开发者的测验统计数据,今天,我们非常乐意 ...

  5. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  6. 20172319 2018.04.11 《Java程序设计教程》第7周课堂测验(补写博客)

    20172319 2018.04.11 <Java程序设计教程>第7周课堂测验 课程:<程序设计与数据结构> 班级:1723 学生:唐才铭 学号:20172319 指导老师:王 ...

  7. Java 第一次课堂测验

    周一下午进行了开学来java第一次课堂测验,在课堂上我只完成了其中一部分,现代码修改如下: 先定义 ScoreInformation 类记录学生信息: /** * 信1805-1 * 胡一鸣 * 20 ...

  8. Java web 小测验

    题目要求: 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求显示“• ”或“*”表示输入位数,密码要求八位以上字母.数字组成.(1分) 3性别:要求用单 ...

  9. 第一周java测验感想

     在正式开学的第一周,建民老师就给我们来了一个下马威.我本身的编程基础比较差,不知道怎么去想,怎么去一步步的去完成这么一个工程.所以我在星期四的下午十分的痛苦…因为不知道怎么搞嘛.尽管在暑假的时候看了 ...

随机推荐

  1. hdoj:2085

    核反应堆 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. Efficient Online Segmentation for Sparse 3D Laser Scans-- 在线的稀疏点云分割

    在基于激光的自动驾驶或者移动机器人的应用中,在移动场景中提取单个对象的能力是十分重要的.因为这样的系统需要在动态的感知环境中感知到周围发生变化或者移动的对象,在感知系统中,将图像或者点云数据预处理成单 ...

  3. HTTP 02 HTTP1.1 协议

    发送请求: 返回时, content-type 与 HTTP 正文之间有一个空格 HTTP 是不保存状态协议, 也就是说在 HTTP 这个级别, 协议对于发送过的请求或相应都不做持久化处理. 但是, ...

  4. Houdini技术体系 基础管线(四) :Houdini驱动的UE4植被系统 下篇

    背景 在上篇中,实现了使用Houdini在UE4里根据地形过程生成植被的最基本的原型.并且支持把植被在UE4里Bake成使用的HierarchicalInstancedStaticMeshCompon ...

  5. 【FM】算法

    https://www.cnblogs.com/AndyJee/p/7879765.html

  6. 手机访问PC网站自动跳转到手机版

    随着智能手机的流行,4G时代来临,手机用户越来越多,在生活中甚至手机比电脑用的还多,当前开发的网站大都是PC和WAP版并存,但是很少有用户愿意去记住一个网站的两个端的不同域名,所以需要我们做一些设置, ...

  7. 对unicode数据进行部分replace

    unicode = u'\u9879\u76ee\u7ba1\u7406\u90e8' print unicode #项目管理部 unicode = unicode.replace("项目& ...

  8. 第四天,通过windows来执行第一个python文件步骤

    该看 第 38部分的啦

  9. linux的基本操作(文本编辑工具vim)

    文本编辑工具vim * 命令模式:在一般模式下,输入”:”或者”/”即可进入命令模式.在该模式下,你可以搜索某个字符或者字符串,也可以保存.替换.退出.显示行号等等. 下面笔者教你如何在一个空白文档中 ...

  10. 7款让人惊叹的HTML5粒子动画特效(转载)

    1.HTML5 Canvas粒子模拟效果 这是一款利用HTML5 Canvas模拟出来的30000个粒子动画,当你用鼠标在canvas画布上移动时,鼠标周围的一些粒子就会跟着你移动,并形成一定的图案, ...