parent
9564cca786
commit
f17a601d68
@ -0,0 +1,110 @@
|
||||
package com.demo;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
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 java.util.*;
|
||||
|
||||
|
||||
import com.dao.ProductionDao;
|
||||
import com.dao.ProductionDaoImpl;
|
||||
|
||||
import com.domain.Production;
|
||||
|
||||
|
||||
@WebServlet(name = "ProductionServlet", urlPatterns = { "/addProduction.do" })
|
||||
public class ProductionServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected void doGet(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException{
|
||||
doPost(request,response);
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
String action = request.getParameter("action");
|
||||
if(action!=null&&action.equals("addProduction")){
|
||||
addProduction(request,response);
|
||||
}else if(action.equals("delete")){
|
||||
deleteProduction(request,response);
|
||||
}else{
|
||||
listProduction(request,response);
|
||||
}
|
||||
}
|
||||
// 添加产品方法
|
||||
public void addProduction(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
int id=Integer.parseInt(request.getParameter("pid"));
|
||||
String price=new String(request.getParameter("price").getBytes("iso-8859-1"),"UTF-8");
|
||||
String prom=new String(request.getParameter("prom").getBytes("iso-8859-1"),"UTF-8");
|
||||
String classify=new String(request.getParameter("classify").getBytes("iso-8859-1"),"UTF-8");
|
||||
String store=new String(request.getParameter("store").getBytes("iso-8859-1"),"UTF-8");
|
||||
Production s = new Production();
|
||||
s.setPid(id);
|
||||
s.setPrice(price);
|
||||
s.setProm(prom);
|
||||
s.setClassify(classify);
|
||||
s.setStore(store);
|
||||
|
||||
|
||||
|
||||
ProductionDao dao = new ProductionDaoImpl();
|
||||
try{
|
||||
boolean success= dao.addProduction(s);
|
||||
if(success){
|
||||
String message = "插入记录成功";
|
||||
request.setAttribute("message", message);
|
||||
listProduction(request,response);
|
||||
}else{
|
||||
RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
|
||||
rd.forward(request, response);
|
||||
}
|
||||
}catch(SQLException e) {}
|
||||
}
|
||||
|
||||
// 显示产品信息
|
||||
public void listProduction(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException{
|
||||
ProductionDao dao = new ProductionDaoImpl();
|
||||
try {
|
||||
List<Production> list= dao.listProduction();
|
||||
request.setAttribute("productionList", list);
|
||||
}catch(SQLException e) {}
|
||||
RequestDispatcher rd = request.getRequestDispatcher("da-production.jsp");
|
||||
rd.forward(request, response);
|
||||
}
|
||||
//删除产品信息
|
||||
public void deleteProduction(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
int id = Integer.parseInt(request.getParameter("id"));
|
||||
ProductionDao dao = new ProductionDaoImpl();
|
||||
try {
|
||||
int success=dao.removeProduction(id);
|
||||
if(success>0){
|
||||
listProduction(request,response);
|
||||
}
|
||||
}catch(SQLException e) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue