www.pudn.com > restrant.zip > MealServlet.java, change:2013-12-23,size:1584b


package com.alex.restrantol.servlet; 
 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.List; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import com.alex.restrantol.dao.MealDao; 
import com.alex.restrantol.entity.MealEntity; 
 
public class MealServlet extends HttpServlet { 
	protected void service(HttpServletRequest req, HttpServletResponse res) 
			throws ServletException, IOException { 
		String type = req.getParameter("type"); 
 
		if ("findall".equals(type)) { 
			findAll(req); 
			req.getRequestDispatcher("/show.jsp").forward(req, res); 
		} else if ("findpart".equals(type)) { 
			findPart(req); 
			req.getRequestDispatcher("/show.jsp").forward(req, res); 
		} else if ("findbyid".equals(type)) { 
			int mealId = new Integer(req.getParameter("mid")).intValue(); 
			findById(mealId, req); 
			req.getRequestDispatcher("/details.jsp").forward(req, res); 
		} 
	} 
 
	protected void findAll(HttpServletRequest req) { 
		List<MealEntity> list = new ArrayList<MealEntity>(); 
		list = new MealDao().findMealAll(); 
		req.setAttribute("mealList", list); 
	} 
 
	protected void findPart(HttpServletRequest req) { 
		List<MealEntity> list = new ArrayList<MealEntity>(); 
		list = new MealDao().findMealPart(); 
		req.setAttribute("mealList", list); 
	} 
 
	protected void findById(int mid, HttpServletRequest req) { 
		MealEntity meal = new MealDao().findMealById(mid); 
		req.setAttribute("meal", meal); 
	} 
}