bidaction.java

来自「Spring +Web 的完整 MyEclipse 项目源码,使用者可以作为入门」· Java 代码 · 共 66 行

JAVA
66
字号
package com.bid.struts;

import java.math.BigDecimal;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;

import com.bid.domain.*;
import com.bid.hibernate.*;
import com.bid.exceptions.BusinessException;


public class BidAction extends Action {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse reponse)
			throws Exception {
		// TODO Auto-generated method stub

		try {
			DynaActionForm bidForm = (DynaActionForm) actionForm;
			Long itemId = (Long) bidForm.get("itemid");
			Long userId = (Long) bidForm.get("userid");
			BigDecimal bidAmount = (BigDecimal) bidForm.get("bidAmount");
			//BigDecimal bidAmount = new BigDecimal(strBidAmount);
			ItemDAO itemDAO = new ItemDAO();
			UserDAO userDAO = new UserDAO();
			

			Item item = itemDAO.getItemById(itemId);
			
			Bid newBid = item.placeBid(userDAO.getUserById(userId), bidAmount,
					itemDAO.getMaxBidAmount(itemId));
						
			request.setAttribute("userBid", bidAmount);
			return mapping.findForward("success");
		} catch (BusinessException ex) {
			ActionErrors errors = new ActionErrors();
			errors.add("BusinessException", new ActionMessage(ex.getMessage()));
			saveErrors(request,errors);
			return mapping.findForward("failure");
		} catch (Exception ex) {
			ActionErrors errors = new ActionErrors();
			errors.add("SystemException", new ActionMessage(ex.getMessage()));
			saveErrors(request,errors);
			return mapping.findForward("failure");
		}
	}
}

⌨️ 快捷键说明

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