Java过关测验
库存物资管理系统
一、背景资料:
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">保 存</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">查 找</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">保 存</button>
</div> </table>
<div class="a">
<a onclick="return check()" href="CourseServlet?method=del&id=${course.id}">删 除</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">修 改</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">查 询</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过关测验的更多相关文章
- java第一次测验
package kaoshi; import java.util.Scanner; public class ScoreManagement { static int t=0; static int ...
- 2019.9.16:java课后测验
一.动手动脑 1. 枚举类型是引用类型, 枚举不属于原始数据类型,它的每个具体值都引用一个特定的对象.相同的值则引用同一个对象. 可以使用“==”和equals()方法直接比对枚举变量的值,换句话说, ...
- 八成Java开发者解答不了的问题
统计数据来自Java“死亡”竞赛——一个针对开发者的迷你测验 几个月前,我们在一个小型网站上发布了一个称为Java“死亡竞赛”的新项目.测验发布后,超过20000位开发者参加了测验.网站以20道关于J ...
- Java基础知识强化14:Java死亡竞赛题目解析
一个小型网站上发布了一个称为Java“死亡竞赛”的新项目.测验发布后,超过20000位开发者参加了测验.网站以20道关于Java的多选题为主.我们得到了众多开发者的测验统计数据,今天,我们非常乐意 ...
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- 20172319 2018.04.11 《Java程序设计教程》第7周课堂测验(补写博客)
20172319 2018.04.11 <Java程序设计教程>第7周课堂测验 课程:<程序设计与数据结构> 班级:1723 学生:唐才铭 学号:20172319 指导老师:王 ...
- Java 第一次课堂测验
周一下午进行了开学来java第一次课堂测验,在课堂上我只完成了其中一部分,现代码修改如下: 先定义 ScoreInformation 类记录学生信息: /** * 信1805-1 * 胡一鸣 * 20 ...
- Java web 小测验
题目要求: 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求显示“• ”或“*”表示输入位数,密码要求八位以上字母.数字组成.(1分) 3性别:要求用单 ...
- 第一周java测验感想
在正式开学的第一周,建民老师就给我们来了一个下马威.我本身的编程基础比较差,不知道怎么去想,怎么去一步步的去完成这么一个工程.所以我在星期四的下午十分的痛苦…因为不知道怎么搞嘛.尽管在暑假的时候看了 ...
随机推荐
- getCanonicalFile与getAbsoluteFile区别
package test; import java.io.File; import java.io.IOException; public class TestFilePath { public st ...
- 寄存器理解 及 X86汇编入门
本文整理自多材料源,感谢原址分享,请查看末尾Url I, 汇编语言分类: 汇编语言和CPU息息相关,但是不能把汇编语言完全等同于CPU的机器指令.不同架构的CPU指令并不相同,如x86,powerpc ...
- Tomcat启动报错:This file is needed to run this program
Tomcat版本为 8.5.29. 1.情景 kill调用tomcat进程后,重启tomcat报如下错误: Cannot find /usr/local/apache-tomcat-/bin/setc ...
- VS F5不编译 F5总是重新编译
遇到奇怪的现象,F5不编译了 右键解决方案-配置管理器-确保项目的生成被勾选 另外一个情况,即使不修改任何代码,每次点击“生成”或者F5,都会重新编译(Debug模式没问题,Release有这个问题, ...
- Zephyr学习(一)Zephyr介绍
Zephyr是一个面向物联网的嵌入式实时操作系统(RTOS),是Linux基金会旗下的一个项目,具有以下特点: 1.安全的,灵活.高可扩展性,支持多种硬件平台(ARM.ARC.X86.xtensa.n ...
- springBoot整合ftp上传图片功能
知识点: springBoot后端项目,接收前端框架传到的图片,把图片上传到ftp图片服务器上 注意:在上传的过程中可能回出现,可以创建文件夹,但是图片上传不了的问题: 尝试了网上的很多方法,最后将f ...
- [原]CentOS 7 chrony 笔记
~]# timedatectl status Local -- :: CST ==> 本地系统实际时间,设置时间timedatectl set-:: 设置日期timedatectl set- 设 ...
- cs231n笔记 (一) 线性分类器
Liner classifier 线性分类器用作图像分类主要有两部分组成:一个是假设函数, 它是原始图像数据到类别的映射.另一个是损失函数,该方法可转化为一个最优化问题,在最优化过程中,将通过更新假设 ...
- tomcat架构分析和源码解读
最近在看<深入分析java web技术内幕>,书中讲解了一部分tomcat的相关知识,我也去查看了一些源码,看了大神们写的代码,我才知道自己就像在做加减乘除一样,这是不行的.还有好多包和类 ...
- [LeetCode] Flip Game II 翻转游戏之二
You are playing the following Flip Game with your friend: Given a string that contains only these tw ...