www.pudn.com > restrant.zip > ClusterServlet.java, change:2014-03-10,size:3152b


package com.alex.restrantol.servlet; 
 
import java.io.IOException; 
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.ClusterDao; 
import com.alex.restrantol.dao.OrderlineDao; 
import com.alex.restrantol.entity.Cluster; 
import com.alex.restrantol.entity.PageEntity; 
import com.alex.restrantol.entity.UserEntity; 
import com.alex.restrantol.service.ClusterService; 
 
public class ClusterServlet extends HttpServlet { 
 
	public void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException { 
			this.doPost(request, response); 
	} 
 
	public void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException { 
			String type = request.getParameter("type"); 
			if("showById".equals(type)){ 
				Cluster cluster = this.getClusterById(request); 
				if(cluster != null){ 
					request.setAttribute("cluster",cluster); 
				} 
			}else if("showAll".equals(type)){ 
				int currentPage = 1; 
				String p = request.getParameter("page"); 
				if(p!=null){ 
					currentPage = Integer.parseInt(p); 
				} 
				//PageEntity pageEntity = new ClusterDao().getPageEntity(currentPage); 
				//request.setAttribute("pageEntity", pageEntity); 
					request.getRequestDispatcher("WEB-INF/activityManage/trackActivity.jsp").forward(request, response); 
			}else if("add".equals(type)){ 
				ClusterService clusterService = new ClusterService(); 
				if(clusterService.addCluster(request, response)){ 
					; 
				}else{ 
					request.getSession().setAttribute("clusterMessage", "发布活动失败 !"); 
				} 
				try { 
					request.getRequestDispatcher("/WEB-INF/status/clusterStatus.jsp").forward(request, response); 
				} catch (IOException e1) { 
					e1.printStackTrace(); 
				} 
			}else if("deleteById".equals(type)){ 
				 
			}else if("replenish".equals(type)){ 
				ClusterService clusterService = new ClusterService(); 
				String tempPath = this.getServletContext().getRealPath("/temp"); 
				String uploadPath = this.getServletContext().getRealPath("/upload"); 
				if(clusterService.replenishCluster(request,response,tempPath,uploadPath)){ 
					; 
				}else{ 
					request.getSession().setAttribute("clusterMessage", "上传文件失败 !"); 
				} 
				try { 
					request.getRequestDispatcher("/WEB-INF/status/clusterStatus.jsp").forward(request, response); 
				} catch (IOException e1) { 
					e1.printStackTrace(); 
				} 
			}else if("publicity".equals(type)){ 
				UserEntity user = (UserEntity) request.getSession().getAttribute("user"); 
				if(user==null){ 
					request.getRequestDispatcher("login.jsp").forward(request, response); 
				}else{ 
					request.getRequestDispatcher("beginCluster.jsp").forward(request, response); 
				} 
			} 
	} 
 
	private Cluster getClusterById(HttpServletRequest request) { 
		int id = Integer.parseInt(request.getParameter("id")); 
		Cluster cluster = new ClusterDao().findClusterById(id); 
		return cluster; 
	} 
 
}