priceaction.java

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

JAVA
95
字号
//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.PriceForm;import book.example.photoprint.po.Price;import book.example.photoprint.po.Shop;import book.example.photoprint.service.PriceService;/** * MyEclipse Struts Creation date: 12-20-2005 *  * XDoclet definition: *  * @struts.action path="priceAction" name="priceForm" input="price_add.jsp" *                parameter="method" scope="request" * @struts.action-forward name="add_success" path="add_success.jsp" * @struts.action-forward name="error" path="/error.jsp" */public class PriceAction extends DispatchAction {	// --------------------------------------------------------- Instance	// Variables	// --------------------------------------------------------- Methods	/**	 * Method execute	 * 	 * @param mapping	 * @param form	 * @param request	 * @param response	 * @return ActionForward	 */	public ActionForward add(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		PriceForm priceForm = (PriceForm) form;		Price price = new Price();		price.setType(priceForm.getType());		price.setPrice(new Double(priceForm.getPrice()));		price.setShop((Shop)request.getSession().getAttribute("shop"));		PriceService service = new PriceService();		try {			service.addPrice(price);		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("error");		}		return this.list(mapping,form,request,response);	}	public ActionForward list(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		PriceService service = new PriceService();		Shop shop=(Shop)request.getSession().getAttribute("shop");		try {			// 获得商店id			String id=request.getParameter("id");			List list = service.listByShopId(shop);			request.setAttribute("list", list);		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("error");		}		return mapping.findForward("list");	}	public ActionForward delete(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		String priceid=request.getParameter("id");		PriceService service = new PriceService();		try {			service.delete(priceid);		} catch (DBException e) {			e.printStackTrace();			return mapping.findForward("error");		}		return this.list(mapping,form,request,response);	}}

⌨️ 快捷键说明

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