Sie sind auf Seite 1von 9

*tạo csdl tên xuatkho

*trong code
*************tạo interface objectxuatkho***********

package code;

public interface objectxuatkho {


public boolean them(objectxuatkho obj);
public boolean xoa(String tensp);
public boolean sua(objectxuatkho obj);
}

***************tạo class xuatkho****************

package code;

public class xuatkho implements objectxuatkho {


String tensp;
String ngayxuat;
String soluong;
String giaxuat;
String khachhang;
public xuatkho(String tensp,String ngayxuat,String soluong,String
giaxuat,String khachhang) {
super();
this.tensp=tensp;
this.ngayxuat=ngayxuat;
this.soluong=soluong;
this.giaxuat=giaxuat;
this.khachhang=khachhang;
}
public String getTensp() {
return tensp;
}
public void setTensp(String tensp) {
this.tensp = tensp;
}
public String getNgayxuat() {
return ngayxuat;
}
public void setNgayxuat(String ngayxuat) {
this.ngayxuat = ngayxuat;
}
public String getSoluong() {
return soluong;
}
public void setSoluong(String soluong) {
this.soluong = soluong;
}
public String getGiaxuat() {
return giaxuat;
}
public void setGiaxuat(String giaxuat) {
this.giaxuat = giaxuat;
}
public String getKhachhang() {
return khachhang;
}
public void setKhachhang(String khachhang) {
this.khachhang = khachhang;
}
@Override
public boolean them(objectxuatkho obj) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean xoa(String tensp) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean sua(objectxuatkho obj) {
// TODO Auto-generated method stub
return false;
}

*******************tạo class xulixuatkho*****************

package code;

public class xulixuatkho implements objectxuatkho{


public boolean them(objectxuatkho obj) {
xuatkho t=(xuatkho) obj;
try {
new Connect().thucthisql("insert into xuatkho
values('"+t.getTensp()+"','"+t.getNgayxuat()+"','"+t.getSoluong()
+"','"+t.getGiaxuat()+"','"+t.getKhachhang()+"')");
return true;
}catch(Exception e) {
e.printStackTrace();
}
return false;
}
public boolean xoa(String tensp) {
try {
new Connect().thucthisql("delete from xuatkho where
tensp='"+tensp+"'");
return true;
}catch(Exception e) {
e.printStackTrace();
}
return false;
}
public boolean sua(objectxuatkho obj) {
xuatkho s=(xuatkho) obj;
try {
new Connect().thucthisql("update xuatkho set
tensp='"+s.getTensp()+"',ngayxuat='"+s.getNgayxuat()+"',soluong='"+s.getSoluong()
+"',giaxuat='"+s.getGiaxuat()+"',khachhang='"+s.getKhachhang()+"' where
tensp='"+s.getTensp()+"'");
return true;
}catch(Exception e) {
e.printStackTrace();
}
return false;
}
}

*************tạo servlet themxuatkho***************

package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import code.xuatkho;
import code.xulixuatkho;

/**
* Servlet implementation class themNCCServlet
*/
public class themxuatkho extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public themxuatkho() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String tensp=request.getParameter("tensp");
String ngayxuat=request.getParameter("ngayxuat");
String soluong=request.getParameter("soluong");
String giaxuat=request.getParameter("giaxuat");
String khachhang=request.getParameter("khachhang");
xuatkho nk=new xuatkho(tensp,ngayxuat,soluong,giaxuat,khachhang);

if(new xulixuatkho().them(nk)) {
HttpSession session=request.getSession();
session.setAttribute("web",nk);
response.sendRedirect("xuatkho.jsp");
}else {
response.sendRedirect("xuatkho.jsp");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

*************tạo servlet xoaxuatkho*************************

package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import code.xulixuatkho;

/**
* Servlet implementation class xoaNCCServlet
*/
public class xoaxuatkho extends HttpServlet {
private static final long serialVersionUID = 1L;
private String mancc;

/**
* @see HttpServlet#HttpServlet()
*/
public xoaxuatkho() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String tensp=request.getParameter("tensp");
if(new xulixuatkho().xoa(tensp)) {
HttpSession session=request.getSession();
session.setAttribute("web",tensp);
response.sendRedirect("xuatkho.jsp");
}else {
response.sendRedirect("xuatkho.jsp");
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

*************tạo servlet suaxuatkho***************

package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import code.xuatkho;
import code.xulixuatkho;

/**
* Servlet implementation class suaNCCServlet
*/
public class suaxuatkho extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public suaxuatkho() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String tensp=request.getParameter("tensp");
String ngayxuat=request.getParameter("ngayxuat");
String soluong=request.getParameter("soluong");
String giaxuat=request.getParameter("giaxuat");
String khachhang=request.getParameter("khachhang");
xuatkho nk=new xuatkho(tensp,ngayxuat,soluong,giaxuat,khachhang);

if(new xulixuatkho().sua(nk)) {
HttpSession session=request.getSession();
session.setAttribute("web",nk);
response.sendRedirect("xuatkho.jsp");
}else {
response.sendRedirect("xuatkho.jsp");
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

**********tạo jsp xuatkho.jsp**************

<%@ page language="java" contentType="text/html; charset=utf-8"


pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="CSS/style.css"/>
<style type="text/css">
body {
background-color: #333;
}
body,td,th {
color: #FFF;
}
</style>
</head>

<body link="#0066FF">
<a href="themxuatkho.jsp" target="_top">Xuất kho</a>
<%@page import="java.sql.ResultSet" %>
<%@page import="code.Connect" %>

<p>&nbsp;</p>
<table width="946" height="109" border="1" align="center">
<%
Connect con=new Connect();
ResultSet rs=con.chondulieu("select * from xuatkho");
%>
<thead>
<tr>
<th width="90" height="45"><font color="#000CC">Tên sản
phẩm</font></th>
<th width="159"><font color="#000CC">Ngày xuất</font></th>
<th width="205"><font color="#000CC">Số lượng</font></th>
<th width="106"><font color="#000CC">Giá xuất</font></th>
<th width="106"><font color="#000CC">Khách hàng</font></th>
<th width="39"></th>
<th width="39"></th>
</tr>
</thead>
<tbody>
<%
while(rs.next()){
%>
<tr>
<td><font color="#000"><%=rs.getString(1) %></font></td>
<td><font color="#000"><%=rs.getString(2) %></font></td>
<td><font color="#000"><%=rs.getString(3) %></font></td>
<td><font color="#000"><%=rs.getString(4) %></font></td>
<td><font color="#000"><%=rs.getString(5) %></font></td>
<td><font color="#000"><a href="xoaxuatkho.jsp?tensp=<%=rs.getString(1)
%>" target="_top">Xoá</a></font></td>
<td><font color="#000"><a href="suaxuatkho.jsp?tensp=<%=rs.getString(1)
%>" target="_top">Sửa</a></font></td>
</tr>
<%
}
%>
</tbody>
</table>

</body>
</html>

***********************tạo jsp themxuatkho.jsp*********************

<%@ page language="java" contentType="text/html; charset=utf-8"


pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<p><font color="#F00">
XUẤT KHO </font></p>
<table align="center">
<form action="themxuatkho" method="post" name="form1" id="form1">

<p>
<label for="textfield7" > Tên sản phẩm </label>
<input type="text" name="tensp" id="textfield7" />

</p>

<p>
<label for="textfield8"> Ngày xuất </label>
<input type="text" name="ngayxuat" id="textfield8" />
</p>

<p>
<label for="textfield9">Số lượng </label>
<input type="text" name="soluong" id="textfield9" />
</p>

<p>
<label for="textfield10">Giá xuất </label>
<input type="text" name="giaxuat" id="textfield10" />
</p>

<p>
<label for="textfield10">Khách hàng </label>
<input type="text" name="khachhang" id="textfield10" />
</p>

<p>
<input type="submit" name="button4" id="button4" align="middle"
value="Thêm" />
</p>

</form>
</table>
</body>
</html>

************tạo jsp xoaxuatkho.jsp****************

<%@ page language="java" contentType="text/html; charset=utf-8"


pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<p><font color="#F00">
XUẤT KHO </font></p>
<table align="center">
<form action="xoaxuatkho" method="post" name="form1" id="form1">
<%String tensp=request.getParameter("tensp"); %>
<p>
<label for="textfield7" > Tên sản phẩm </label>
<input type="text" name="tensp" value="<%=tensp%>"
id="textfield7" />
<input type="submit" name="button4" id="button4" align="middle"
value="Xoá" />
</p>
</form>
</table>
</body>
</html>

*******************tạo jsp suaxuatkho.jsp****************


<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<p><font color="#F00">
XUẤT KHO </font></p>
<table align="center">
<form action="suaxuatkho" method="post" name="form1" id="form1">
<%String tensp=request.getParameter("tensp"); %>
<p>
<label for="textfield7" > Tên sản phẩm </label>
<input type="text" name="tensp" value="<%=tensp%>"
id="textfield7" />

</p>

<p>
<label for="textfield8"> Ngày xuất </label>
<input type="text" name="ngayxuat" id="textfield8" />
</p>

<p>
<label for="textfield9">Số lượng </label>
<input type="text" name="soluong" id="textfield9" />
</p>

<p>
<label for="textfield10">Giá xuất </label>
<input type="text" name="giaxuat" id="textfield10" />
</p>

<p>
<label for="textfield10">Khách hàng </label>
<input type="text" name="khachhang" id="textfield10" />
</p>

<p>
<input type="submit" name="button4" id="button4" align="middle"
value="Sửa" />
</p>

</form>
</table>
</body>
</html>