⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addfoodbill.java

📁 酒店管理系统
💻 JAVA
字号:
package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import database.*;
import javabean.*;

public class AddFoodBill extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public AddFoodBill() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		HttpSession session = request.getSession();
		connectDB con = new connectDB();
		Customer customer = (Customer)session.getAttribute("customer");
		String identifierID = customer.getIdentifierID();
		DietBillTable dietBill = (DietBillTable)session.getAttribute("dietBill");
		String foods[] = dietBill.getFoods();
		double totalcost = 0;
		if(foods != null && foods.length != 0){
			for(int i = 0;i < foods.length; i++){
				try{
					int foodNumber = dietBill.getFoodNumber(foods[i]);
					String sql1 = "select foodNumber from customerDiet where identifierID = '" + identifierID + "' and foodID = '" + foods[i] + "'";
					con.excuteQuery(sql1);
					if(con.next()){
						int num = con.getInt(1);
						num += foodNumber;
						String sql2 = "Update customerDiet set foodNumber = '" + num +"' where identifierID = '" + identifierID + "' and foodID = '" + foods[i] + "'";
						con.excuteUpdate(sql2);
					}else{
						String sql3 = "insert into customerDiet values('" + identifierID + "','" + foods[i] + "','" + foodNumber + "')";
						con.excuteQuery(sql3);
					}
				}catch(Exception e){
	    		 e.printStackTrace();
				}
				
				if(foods[i] != null){
					int num = dietBill.getFoodNumber(foods[i]);
					for(int j = 0;j < num;j++)
						dietBill.removeItem(foods[i]);
					
				}
			}
	    }
		
		
		
		response.sendRedirect("/hotel/foodIdentifierID.jsp");
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -