Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.ba.reports.collection; import com.ba.util.BAHandleAllException; import com.ba.util.BAUtil; import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.struts.actions.DispatchAction; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionForward; import org.json.simple.JSONObject; /** * * @author RAPID */ public class BACollectionAction extends DispatchAction { /* forward name="success" path="" */ private final static String SUCCESS = "success"; public static double totalAdvPaid = 0; public static double totalReceipt = 0; public static double totalFoodBill = 0; public static double totalServiceBill = 0; public static double totalSettlement = 0; private static Logger logger = Logger.getLogger(BACollectionAction.class); public ActionForward loadCollection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { logger.info(" loadCollection method starts here"); return mapping.findForward(SUCCESS); } public ActionForward baView(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("view()"); JSONObject json = new JSONObject(); BACollectionDTO vo = new BACollectionDTO(); try { logger.info(" view method starts here"); String fromDate = request.getParameter("fromDate"); String toDate = request.getParameter("toDate"); List hashMpAdvanceCollectedDet = BACollectionFactory.getInstanceOfBACollectionFactory() .getAdvanceCollected(fromDate, toDate); List hashMpgetReceiptsDet = BACollectionFactory.getInstanceOfBACollectionFactory().getReceipts(fromDate, toDate); List hashMpgetFoodBillDet = BACollectionFactory.getInstanceOfBACollectionFactory() .getFoodBills(fromDate, toDate); List hashMpgetServiceBillsDet = BACollectionFactory.getInstanceOfBACollectionFactory() .getServiceBills(fromDate, toDate); List hashMpgetSettlementsDet = BACollectionFactory.getInstanceOfBACollectionFactory() .getSettlements(fromDate, toDate); double collectionSum = BAUtil.getDoubleValue(totalAdvPaid + "") + BAUtil.getDoubleValue(totalReceipt + "") + BAUtil.getDoubleValue(totalFoodBill + "") + BAUtil.getDoubleValue(totalServiceBill + "") + BAUtil.getDoubleValue(totalSettlement + ""); logger.info(hashMpAdvanceCollectedDet + "hashMpAdvanceCollectedDet"); logger.info(hashMpgetReceiptsDet + "hashMpgetReceiptsDet"); json.put("exception", ""); json.put("hashMpAdvanceCollectedDet", hashMpAdvanceCollectedDet); json.put("hashMpAdvanceCollectedDetExit", hashMpAdvanceCollectedDet.size()); json.put("hashMpgetReceiptsDet", hashMpgetReceiptsDet); json.put("hashMpgetReceiptsDetExit", hashMpAdvanceCollectedDet.size()); json.put("hashMpgetFoodBillDet", hashMpgetFoodBillDet); json.put("hashMpgetFoodBillDetExit", hashMpgetFoodBillDet.size()); json.put("hashMpgetServiceBillsDet", hashMpgetServiceBillsDet); json.put("hashMpgetServiceBillsDetExit", hashMpgetServiceBillsDet.size()); json.put("hashMpgetSettlementsDet", hashMpgetSettlementsDet); json.put("hashMpgetSettlementsDetExit", hashMpgetSettlementsDet.size()); json.put("collectionSum", collectionSum); } catch (Exception ex) { logger.error("The Exception is :" + ex); ex.printStackTrace(); json.put("exception", BAHandleAllException.exceptionHandler(ex)); } response.getWriter().write(json.toString()); return null; } }