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

📄 manageraction.java

📁 shoppingCar 购物车
💻 JAVA
字号:
package com.tarena.shoppingcar.action;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionMessage;import org.apache.struts.action.ActionMessages;import org.apache.struts.actions.MappingDispatchAction;import com.tarena.shoppingcar.biz.OrderBiz;import com.tarena.shoppingcar.biz.ProductBiz;import com.tarena.shoppingcar.biz.UserBiz;import com.tarena.shoppingcar.entity.Order;import com.tarena.shoppingcar.entity.Product;import com.tarena.shoppingcar.entity.User;import com.tarena.shoppingcar.util.PaginationInfo;public class ManagerAction extends MappingDispatchAction {	private ProductBiz pb = new ProductBiz();	private UserBiz ub = new UserBiz();	private OrderBiz ob = new OrderBiz();		public ActionForward mproduct(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			PaginationInfo info = new PaginationInfo();			info.setRowPerPage(6);			int rowCount = pb.getRowCount();			info.setRowCount(rowCount);			List<Product> products = pb.findByPage(info.getStartRow(), info					.getRowPerPage());			request.setAttribute("products", products);			session.setAttribute("info", info);			forward = mapping.findForward("productList");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("product.list"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward firstPage(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			PaginationInfo info = (PaginationInfo) session.getAttribute("info");			info.firstPage();			List<Product> products = pb.findByPage(info.getStartRow(), info					.getRowPerPage());			request.setAttribute("products", products);			forward = mapping.findForward("success");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("page.first"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward lastPage(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			PaginationInfo info = (PaginationInfo) session.getAttribute("info");			info.lastPage();			List<Product> products = pb.findByPage(info.getStartRow(), info					.getRowPerPage());			request.setAttribute("products", products);			forward = mapping.findForward("success");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("page.last"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward nextPage(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			PaginationInfo info = (PaginationInfo) session.getAttribute("info");			info.nextPage();			List<Product> products = pb.findByPage(info.getStartRow(), info					.getRowPerPage());			request.setAttribute("products", products);			forward = mapping.findForward("success");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("page.next"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward previousPage(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			PaginationInfo info = (PaginationInfo) session.getAttribute("info");			info.previousPage();			List<Product> products = pb.findByPage(info.getStartRow(), info					.getRowPerPage());			request.setAttribute("products", products);			forward = mapping.findForward("success");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("page.previous"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward gotoPage(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			PaginationInfo info = (PaginationInfo) session.getAttribute("info");			String pageNo = request.getParameter("pageNo");			info.gotoPage(Integer.parseInt(pageNo));			List<Product> products = pb.findByPage(info.getStartRow(), info					.getRowPerPage());			request.setAttribute("products", products);			forward = mapping.findForward("success");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("page.goto"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward findBySession(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			PaginationInfo info = (PaginationInfo) session.getAttribute("info");			int currentPage = info.getCurrentPage();			info.gotoPage(currentPage);			List<Product> products = pb.findByPage(info.getStartRow(), info					.getRowPerPage());			request.setAttribute("products", products);			forward = mapping.findForward("success");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("system.center"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward logout(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			HttpSession session = request.getSession();			session.invalidate();			forward = mapping.findForward("success");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("user.logout"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward delete(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		int id = Integer.parseInt(request.getParameter("id"));		pb.remove(id);		forward = mapping.findForward("success");		return forward;	}	public ActionForward toedit(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		int id = Integer.parseInt(request.getParameter("id"));		Product product = pb.findById(id);		request.setAttribute("product", product);		forward = mapping.findForward("success");		return forward;	}	public ActionForward edit(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {				ActionForward forward = null;		String sid = request.getParameter("id");		int id = Integer.parseInt(sid);		String pname = request.getParameter("pname");		String discription = request.getParameter("discription");		String dprice = request.getParameter("price");		double price = Double.parseDouble(dprice);		Product product = new Product();		product.setId(id);		product.setPname(pname);		product.setDiscription(discription);		product.setPrice(price);		pb.modify(product);		forward = mapping.findForward("success");		return forward;	}	public ActionForward add(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {				ActionForward forward = null;		String pname = request.getParameter("pname");		String discription = request.getParameter("discription");		String dprice = request.getParameter("price");		double price = Double.parseDouble(dprice);		Product product = new Product();		product.setPname(pname);		product.setDiscription(discription);		product.setPrice(price);		pb.add(product);		forward = mapping.findForward("success");		return forward;	}	//***********定单管理************//	public ActionForward order(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			List<Order> orders = ob.getOrders();			request.setAttribute("orders", orders);			forward = mapping.findForward("orderList");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("order.list"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward findOrder(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			String oid = request.getParameter("oid");			List<Order> orders = ob.findByOid(oid);			request.setAttribute("orders", orders);			forward = mapping.findForward("order");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("findOrder.list"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward viewProduct(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			String id = request.getParameter("id");			List<Product> products = pb.findByOrderID(Integer.parseInt(id));			request.setAttribute("products", products);			forward = mapping.findForward("product");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("viewproduc.list"));			forward = mapping.findForward("error");		}		return forward;	}	//********用户管理**************//	public ActionForward user(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			List<User> users = ub.getUsers();			request.setAttribute("users", users);			forward = mapping.findForward("userList");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("user.list"));			forward = mapping.findForward("error");		}		return forward;	}	public ActionForward findUser(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		ActionForward forward = null;		try {			String userName = request.getParameter("userName");			List<User> users = ub.findByName(userName);			System.out.println(users.size());			request.setAttribute("users", users);			forward = mapping.findForward("user");		} catch (Exception e) {			e.printStackTrace();			saveErrors(request, getMessages("findOrder.list"));			forward = mapping.findForward("error");		}		return forward;	}			private ActionMessages getMessages(String key) {		ActionMessages errors = new ActionMessages();		ActionMessage message = new ActionMessage(key);		errors.add("error", message);		return errors;	}}

⌨️ 快捷键说明

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