1. 程式人生 > >商品資訊管理系統

商品資訊管理系統

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.Product;
import com.hjf.util.DBUtil;

/**
 * 課程Dao
 * Dao層操作資料
 * @author Zheng
 *
 */
public
class ProductDao { /** * 新增 增 * @param course * @return */ public boolean add(Product product) { String sql = "insert into product(name, home, type, guige, num, data, time, people) values('" + product.getName() + "','" + product.getHome() + "','" + product.getType() + "
','"+product.getGuige()+"','"+product.getNum()+"','"+product.getData()+"','"+product.getTime()+"','"+product.getPeople()+"')"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); state.executeUpdate(sql); }
catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } return f; } /** * 刪除 * *引數 @param id * @return */ public boolean delete (int id) { String sql = "delete from product where id='" + id + "'"; 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; } /** * 修改 * @param name * @param pass */ public boolean update(Product product) { String sql = "update product set name='" + product.getName() + "', home='" + product.getHome() + "', type='" + product.getType() + "',guige='" + product.getGuige() + "',num='" + product.getNum() + "',data='" + product.getData() + "',time='" + product.getTime() + "',people='" + product.getPeople() + "' where id='" + product.getId() + "'"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); a = state.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } return f; } /** * 驗證商品名稱是否唯一 * true --- 不唯一 * @param name * @return */ public boolean name(String name) { boolean flag = false; String sql = "select name from product where name = '" + name + "'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return flag; } /** * 通過ID得到類 * @param id * @return */ public Product getProductById(int id) { String sql = "select * from product where id ='" + id + "'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; Product product = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { String name = rs.getString("name"); String home = rs.getString("home"); String type = rs.getString("type"); String guige=rs.getString("guige"); String num=rs.getString("num"); String data=rs.getString("data"); String time=rs.getString("time"); String people=rs.getString("people"); product = new Product(id, name, home, type, guige, num, data, time, people); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return product; } /** * 通過name得到Product * @param name * @return */ public Product getProductByName(String name) { String sql = "select * from product where name ='" + name + "'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; Product product = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { int id = rs.getInt("id"); String home = rs.getString("home"); String type = rs.getString("type"); String guige = rs.getString("guige"); String num=rs.getString("num"); String data=rs.getString("data"); String time=rs.getString("time"); String people=rs.getString("people"); product = new Product(id, name, home, type, guige, num, data, time, people); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return product; } /** * 查詢 * @param name * @param home * @param type * @param guige * @param num * @return */ public List<Product> search(String name, String data) { String sql = "select * from product where "; if (name != "") { sql += "name like '%" + name + "%'"; } if (data != "") { sql += "data like '%" + data + "%'"; } List<Product> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Product bean = null; while (rs.next()) { int id = rs.getInt("id"); String name2 = rs.getString("name"); String home2=rs.getString("home"); String type2=rs.getString("type"); String guige2=rs.getString("guige"); String num2=rs.getString("num"); String data2=rs.getString("data"); String time2=rs.getString("time"); String people2=rs.getString("people"); bean = new Product(id, name2, home2, type2, guige2, num2, data2, time2, people2); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } /** * 全部資料 * @param name * @param home * @param type * @param guige * @param num * @param data * @param time * @param people * @return */ public List<Product> list() { String sql = "select * from product"; List<Product> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Product bean = null; while (rs.next()) { int id = rs.getInt("id"); String name2 = rs.getString("name"); String home2 = rs.getString("home"); String type2 = rs.getString("type"); String guige2 = rs.getString("guige"); String num2=rs.getString("num"); String data2=rs.getString("data"); String time2=rs.getString("time"); String people2=rs.getString("people"); bean = new Product(id, name2, home2, type2, guige2, num2, data2, time2, people2); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } }
dao層負責對資料庫的基本操作,進行增刪改查的操作
在資料的寫入時一定要注意順序,否則將帶來不可挽回的錯誤
package com.hjf.entity;

public class Product {

	private int id;
	private String name;
	private String home;
	private String type;
	private String guige;
	private String num;
	private String data;
	private String time;
	private String people;
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getHome() {
		return home;
	}
	public void setHome(String home) {
		this.home = home;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getGuige() {
		return guige;
	}
	public void setGuige(String guige) {
		this.guige = guige;
	}
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num=num;
	}
	public String getData() {
		return data;
	}
	public void setData(String data) {
		this.data = data;
	}
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	public String getPeople() {
		return people;
	}
	public void setPeople(String people) {
		this.people = people;
	}
	public Product() {}
	//*構造方法
	public Product(int id, String name, String home, String type,String guige,String num,String data,String time,String people) {
		this.id = id;
		this.home = home;
		this.type = type;
		this.guige = guige;
		this.num=num;
		this.data=data;
		this.time=time;
		this.people=people;
		this.name=name;
	}
	public Product(String name, String home, String type,String guige,String num,String data,String time,String people) {
		this.home = home;
		this.type = type;
		this.guige = guige;
		this.num=num;
		this.data=data;
		this.time=time;
		this.people=people;
		this.name=name;
	}
	public Product(int id,String data,String name) {
		this.id = id;
		this.data=data;
		this.name=name;
	}
}

實體類Product初始化所需要的變數,併為變數增加get、set方法並設定建構函式
package com.hjf.service;

import java.util.List;

import com.hjf.dao.ProductDao;
import com.hjf.entity.Product;

/**
 * CourseService
 * 服務層
 * @author Zheng
 *
 */
public class ProductService {

	ProductDao pDao = new ProductDao();
	
	/**
	 * 新增
	 * @param course
	 * @return
	 */
	public boolean add(Product product) {
		boolean f = false;
		if(!pDao.name(product.getName())) {
			pDao.add(product);
			f = true;
		}
		return f;
	}
	
	/**
	 * 刪除
	 */
	public void del(int id) {
		pDao.delete(id);
	}
	
	/**
	 * 修改
	 * @return 
	 */
	public void update(Product product) {
		pDao.update(product);
	}
	
	/**
	 * 通過ID得到一個Product
	 * @return 
	 */
	public Product getProductById(int id) {
		return pDao.getProductById(id);
	}

	/**
	 * 通過Name得到一個Course
	 * @return 
	 */
	public Product getProductByName(String name) {
		return pDao.getProductByName(name);
	}
	
	/**
	 * 查詢
	 * @return 
	 */
	public List<Product> search(String name, String data) {
		return pDao.search(name, data);
	}
	
	/**
	 * 全部資料
	 * @return 
	 */
	public List<Product> list() {
		return pDao.list();
	}
}
用於服務
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.Product;
import com.hjf.service.ProductService;

@WebServlet("/ProductServlet")
public class ProductServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	ProductService service = new ProductService();
	
	/**
	 * 方法選擇
	 */
	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 ("getproductbyid".equals(method)) {
			getProductById(req, resp);
		} else if ("getproductbyname".equals(method)) {
			getProductByName(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 home = req.getParameter("home");
		String type = req.getParameter("type");
		String guige = req.getParameter("guige");
		String num = req.getParameter("num");
		String data = req.getParameter("data");
		String time = req.getParameter("time");
		String people = req.getParameter("people");
		Product product = new Product(name, home, type, guige, num, data, time, people);
		
		//新增後訊息顯示
		if(service.add(product)) {
			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<Product> products = service.list();
		req.setAttribute("products", products);
		for(int i = 0; i < products.size(); i++) {
			System.out.println(products.get(i).getName());
		}
		req.getRequestDispatcher("list.jsp").forward(req,resp);
	}

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

	/**
	 * 通過名字查詢
	 * 跳轉至刪除
	 * @param req
	 * @param resp
	 * @throws IOException
	 * @throws ServletException 
	 */
	private void getProductByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		req.setCharacterEncoding("utf-8");
		String name = req.getParameter("name");
		Product product = service.getProductByName(name);
		if(product == null) {
			req.setAttribute("message", "查無此商品!");
			req.getRequestDispatcher("del.jsp").forward(req,resp);
		} else {
			req.setAttribute("product", product);
			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");
		String name = req.getParameter("name");
		String home = req.getParameter("home");
		String type = req.getParameter("type");
		String guige = req.getParameter("guige");
		String num = req.getParameter("num");
		String data = req.getParameter("data");
		String time = req.getParameter("time");
		String people = req.getParameter("people");
		Product product = new Product(name, home, type, guige, num, data, time, people);
		
		service.update(product);
		req.setAttribute("message", "修改成功");
		req.getRequestDispatcher("ProductServlet?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 data = req.getParameter("data");
		
		List<Product> products = service.search(name, data);
		req.setAttribute("products", products);
		req.getRequestDispatcher("searchlist.jsp").forward(req,resp);
	}
}

  用於對各jsp檔案之間進行跳轉等操作

package com.hjf.util;
//資料庫連線
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 資料庫連線工具
 * @author Zheng
 *
 */
public class DBUtil {
	
	public static String db_url = "jdbc:mysql://localhost:3306/test?useSSL=false";
	public static String db_user = "root";
	public static String db_pass = "root";
	
	public static Connection getConn () {
		Connection conn = null;
		
		try {
			Class.forName("com.mysql.jdbc.Driver");//載入驅動
			conn = DriverManager.getConnection(db_url, db_user, db_pass);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return conn;
	}
	
	/**
	 * 關閉連線
	 * @param state
	 * @param conn
	 */
	public static void close (Statement state, Connection conn) {
		if (state != null) {
			try {
				state.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void close (ResultSet rs, Statement state, Connection conn) {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if (state != null) {
			try {
				state.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
連結資料庫的公式,很實用改個密碼、資料庫名便可以輕鬆上手
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>寫入</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
</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=add" method="post" onsubmit="return check()">
			<div class="a">
				商品名稱<input type="text" id="name" name="name"/>
			</div>
			<div class="a">
				生產廠家<input type="text" id="home" name="home" />
			</div>
			<div class="a">
				型號<input type="text" id="type" name="type" />
			</div>
			<div class="a">
				規格<input type="text" id="guige" name="guige" />
			</div>
			<div class="a">
				數量<input type="text" id="num" name="num" />
			</div>
			<div class="a">
				日期<input type="text" id="data" name="data" />
			</div>
			<div class="a">
				時間<input type="text" id="time" name="time" />
			</div>
			<div class="a">
				入庫單位及姓名<input type="text" id="people" name="people" />
			</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 home = document.getElementById("home");
			var type = document.getElementById("type");
			var guige = document.getElementById("guige");
			var num = document.getElementById("num");
			var data = document.getElementById("data");
			var time = document.getElementById("time");
			var people = document.getElementById("people");
			//非空
			if(name.value == '') {
				alert('商品名稱為空');
				name.focus();
				return false;
			}
			if(home.value == '') {
				alert('生產廠家為空');
				home.focus();
				return false;
			}
			if(type.value == '') {
				alert('型號為空');
				type.focus();
				return false;
			}
			if(guige.value == '') {
				alert('規格為空');
				guige.focus();
				return false;
			}
			if(num.value == '') {
				alert('數量為空');
				num.focus();
				return false;
			}
			if(data.value == '') {
				alert('日期為空');
				data.focus();
				return false;
			}
			if(time.value == '') {
				alert('時間為空');
				time.focus();
				return false;
			}
			if(people.value == '') {
				alert('入庫單位為空');
				type.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: white;
		background-color: greenyellow;
	}
</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="ProductServlet?method=getproductbyname" 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");;
			
			//非空
			if(name.value == '') {
				alert('商品名稱為空');
				name.focus();
				return false;
			}
		}
	</script>
</body>
</html>

用於刪除的jsp
del.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{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
	.tb, td {
		border: 1px solid black;
		font-size: 22px;
	}
</style>
</head>
<body>
	<div align="center">
		<h1 style="color: red;">商品資訊刪除</h1>
		<a href="index.jsp">返回主頁</a>
		<table class="tb">
			<tr>
				<td>商品名稱</td>
				<td>${product.name}</td>
			</tr>
			<tr>
				<td>生產廠家</td>
				<td>${product.home}</td>
			</tr>
			<tr>
				<td>型號</td>
				<td>${product.type}</td>
			</tr>
			<tr>
				<td>規格</td>
				<td>${product.guige}</td>
			</tr>
			<tr>
				<td>數量</td>
				<td>${product.num}</td>
			</tr>
			<tr>
				<td>日期</td>
				<td>${product.data}</td>
			</tr>
			<tr>
				<td>時間</td>
				<td>${product.time}</td>
			</tr>
			<tr>
				<td>入庫單位及姓名</td>
				<td>${product.people}</td>
			</tr>
		</table>
		<div class="a">
			<a onclick="return check()" href="ProductServlet?method=del&id=${product.id}">刪   除</a>
		</div>
	</div>
	<script type="text/javascript">
		function check() {
			if (confirm("真的要刪除嗎?")){
				return true;
			}else{
				return false;
			}
		}
	</script>
</body>
</html>


detail.jsp

  

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品資訊修改頁面</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
</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="ProductServlet?method=update" method="post" onsubmit="return check()">
			<div class="a">
				商品名稱<input type="text" id="name" name="name" value="${product.name}"/>
			</div>
			<div class="a">
				生產廠家<input type="text" id="home" name="home" value="${product.home}"/>
			</div>
			<div class="a">
				型號<input type="text" id="type" name="type" value="${product.type}"/>
			</div>
			<div class="a">
				規格<input type="text" id="guige" name="guige" value="${product.guige}"/>
			</div>
			<div class="a">
				數量<input type="text" id="num" name="num" value="${product.num}"/>
			</div>
			<div class="a">
				日期<input type="text" id="data" name="data" value="${product.data}"/>
			</div>
			<div class="a">
				時間<input type="text" id="time" name="time" value="${product.time}"/>
			</div>
			<div class="a">
				入庫單位及姓名<input type="text" id="people" name="people" value="${product.people}"/>
			</div>
			<input type="hidden" id="id" name="id" value="${product.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 home = document.getElementById("home");
			var type = document.getElementById("type");
			var guige = document.getElementById("guige");
			var num = document.getElementById("num");
			var data = document.getElementById("data");
			var time = document.getElementById("time");
			var people = document.getElementById("people");
			//非空
			if(name.value == '') {
				alert('商品名稱為空');
				name.focus();
				return false;
			}
			if(home.value == '') {
				alert('生產廠家為空');
				home.focus();
				return false;
			}
			if(type.value == '') {
				alert('型號為空');
				type.focus();
				return false;
			}
			if(guige.value == '') {
				alert('規格為空');
				guige.focus();
				return false;
			}
			if(num.value == '') {
				alert('數量為空');
				num.focus();
				return false;
			}
			if(data.value == '') {
				alert('日期為空');
				data.focus();
				return false;
			}
			if(time.value == '') {
				alert('時間為空');
				time.focus();
				return false;
			}
			if(people.value == '') {
				alert('入庫單位為空');
				people.focus();
				return false;
			}
			
			
			
		}
	</script>
</body>
</html>

  

<%@ 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="ProductServlet?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>

  

<%@ 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: white;
		background-color: greenyellow;
	}
	.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>數量</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.type}</td>
					<td>${item.guige}</td>
					<td>${item.num}</td>
					<td>${item.data}</td>
					<td>${item.time}</td>
					<td>${item.people}</td>
					<td><a href="CourseServlet?method=getcoursebyid&id=${item.id}">修改</a></td>
				</tr>
			</c:forEach>
		</table>
	</div>
</body>
</html>

  

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.a{
		margin-top: 20px;
	}
	.b{
		font-size: 20px;
		width: 160px;
		color: white;
		background-color: greenyellow;
	}
</style>
</head>
<body>
	<div align="center">
		<h1 style="color: red;">商品資訊查詢</h1>
		<a href="index.jsp">返回主頁</a>
		<form action="ProductServlet?method=search" method="post" onsubmit="return check()">
			<div class="a">
				商品名稱<input type="text" id="name" name="name"/>
			</div>
			<div class="a">
				日期<input type="text" id="data" name="data" />
			</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 data = document.getElementById("data");
			
			//非空
			if(name.value == '' && data.value == '') {
				alert('請填寫一個條件');
				return false;
			}
		}
	</script>
</body>
</html>

  

<%@ 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>查詢資訊列表</title>
<style>
    .a{
        margin-top: 20px;
    }
    .b{
        font-size: 20px;
        width: 160px;
        color: white;
        background-color: greenyellow;
    }
    .tb, td {
        border: 1px solid black;
        font-size: 22px;
    }
</style>
</head>
<body>
    <div align="center">
        <h1 style="color: 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>
            </tr>
            <!-- forEach遍歷出adminBeans -->
            <c:forEach items="${products}" var="item" varStatus="status">
                <tr>
                    <td>${item.id}</td>
                    <td>${item.name}</td>
                    <td>${item.home}</td>
                    <td>${item.type}</td>
                    <td>${item.guige}</td>
                    <td>${item.num}</td>
                    <td>${item.data}</td>
                    <td>${item.time}</td>
                    <td>${item.people}</td>
                </tr>
            </c:forEach>
        </table>
    </div>
</body>
</html>

這樣就算只是完成了一半還差出庫入庫的單子需要列印並輸出!