shopaction.java

来自「《JSP网站开发典型模块与实例精讲》一书光盘源码」· Java 代码 · 共 151 行

JAVA
151
字号
//Created by MyEclipse Struts// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.0/xslt/JavaClass.xslpackage book.example.photoprint.action;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction;import book.example.photoprint.exception.DBException;import book.example.photoprint.form.ShopForm;import book.example.photoprint.form.UserForm;import book.example.photoprint.po.Shop;import book.example.photoprint.po.User;import book.example.photoprint.service.OrderService;import book.example.photoprint.service.ShopService;import book.example.photoprint.service.UserService;public class ShopAction extends DispatchAction {	public ActionForward add(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		ShopForm shopForm = (ShopForm) form;		Shop shop = new Shop();		shop.setOwner(shopForm.getOwner());		shop.setLoginname(shopForm.getLoginname());		shop.setPasswd(shopForm.getPasswd());		shop.setShopname(shopForm.getShopname());		shop.setTel(shopForm.getTel());		shop.setCellphone(shopForm.getCellphone());		shop.setAddress(shopForm.getAddress());		shop.setStatus(new Integer("1"));		shop.setDescription(shopForm.getDescription());		ShopService service = new ShopService();		try {			// 新添加			if (shopForm.getId() == null||"".equals(shopForm.getId())) {				if (service.getShopByLoginname(shop.getLoginname()) == null) {					service.addShop(shop);					return mapping.findForward("add_success");				} else {					request.setAttribute("info","用户名已经存在");					return mapping.findForward("error");				}			} else {				// 修改shop				shop.setId(shopForm.getId());				service.addShop(shop);				request.getSession().setAttribute("shop",shop);				return this.preModify(mapping,form,request,response);			}		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("error");		}	}	public ActionForward centify(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		try {			String shopId = request.getParameter("shopid");			ShopService service = new ShopService();			service.centify(shopId);		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("error");		}		return mapping.findForward("centify_success");	}	public ActionForward list(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		ShopService service = new ShopService();		try {			List list = service.list();			request.setAttribute("list", list);		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("error");		}		return mapping.findForward("list");	}	public ActionForward list2(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		ShopService service = new ShopService();		String action = request.getParameter("action");		request.setAttribute("action", action);		try {			List list = service.list2();			request.setAttribute("list", list);		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("error");		}		return mapping.findForward("list");	}	public ActionForward login(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		ShopForm shopForm = (ShopForm) form;		String loginname = shopForm.getLoginname();		ShopService service = new ShopService();		Shop shop = null;		try {			shop = service.getShopByLoginname(loginname);		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("loginerror");		}		if (shop == null || !shop.getPasswd().equals(shopForm.getPasswd())) {			return mapping.findForward("loginerror");		}		request.getSession().setAttribute("shop", shop);		return mapping.findForward("loginsuccess");	}	public ActionForward preModify(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		ShopForm shopForm = new ShopForm();		Shop shop = (Shop) request.getSession().getAttribute("shop");		if (shop != null) {			shopForm.setId(shop.getId());			shopForm.setLoginname(shop.getLoginname());			shopForm.setOwner(shop.getOwner());			shopForm.setAddress(shop.getAddress());			shopForm.setPasswd(shop.getPasswd());			shopForm.setCellphone(shop.getCellphone());			shopForm.setDescription(shop.getDescription());			shopForm.setShopname(shop.getShopname());			shopForm.setTel(shop.getTel());			shopForm.setDescription(shop.getDescription());		}		request.setAttribute("shopForm", shopForm);		return mapping.findForward("modify");	}}

⌨️ 快捷键说明

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