sop没有在tomcat7控制台上打印?

时间:2012-06-11 11:21:54

标签: java servlets tomcat7

我打印出一些内容到sop,但是当应用程序启动时,没有在tomcat控制台上打印sop。这是我的代码:

package org.slingemp.attendance;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Part;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slingemp.common.Workindays;

/**
 * Servlet implementation class LeaveReportServlet
 */
@WebServlet(urlPatterns = "/ReadEmployeeAttendance")
@MultipartConfig
public class LeaveReportServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public LeaveReportServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession(true);
        for (Part part : request.getParts()) {
            InputStream is = request.getPart(part.getName()).getInputStream();
            int i = is.available();
            byte[] b = new byte[i];
            is.read(b);
            String fileName = getFileName(part);
            session.setAttribute("accesscardDatafileNname", fileName);
            String uploadDir = getServletContext().getRealPath("/accesscarddata/");
            FileOutputStream os = new FileOutputStream(uploadDir + "/"+ fileName);
            os.write(b);
            is.close();
        }

    }

    private String getFileName(Part part) {
        String partHeader = part.getHeader("content-disposition");
        for (String cd : part.getHeader("content-disposition").split(";")) {
            if (cd.trim().startsWith("filename")) {
                return cd.substring(cd.indexOf('=') + 1).trim()
                        .replace("\"", "");
            }
        }
        return null;

    }

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        String path = getServletContext().getRealPath("/accesscarddata/");

        doGet(request, response);
        readFile(request, response);
        prepareExcelToEmployeeListToMap(request, response);
        classifyEmployeesMapEntries(request, response);
        prepareReport(request, response);

        response.sendRedirect("upload.jsp");

    }
    protected void readFile(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String fileName = "", employeeAttendanceFilePath = "";
        String _uploadDir = getServletContext().getRealPath("/accesscarddata/");
        HttpSession session = request.getSession(true);
        if (session.getAttribute("accesscardDatafileNname") != null)
            fileName = (String) session.getAttribute("accesscardDatafileNname");

        employeeAttendanceFilePath = _uploadDir + "/" + fileName;
        List sheetData = new ArrayList();
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(employeeAttendanceFilePath);
            HSSFWorkbook workbook = new HSSFWorkbook(fis);
            HSSFSheet sheet = workbook.getSheetAt(0);// gets the first sheet on workbook
            Iterator rows = sheet.rowIterator();
            while (rows.hasNext()) {
                HSSFRow row = (HSSFRow) rows.next();
                Iterator cells = row.cellIterator();
                // count=count+1;
                List data = new ArrayList();
                while (cells.hasNext()) {
                    HSSFCell cell = (HSSFCell) cells.next();
                    data.add(cell);
                }
                sheetData.add(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                fis.close();
            }
        }
        session.setAttribute("sheetData", sheetData);

    }

    protected void prepareExcelToEmployeeListToMap(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

        String strdepartment = "";
        int j = 1;
        boolean isProceed=true;
        List sheetData = null;
        HttpSession session = request.getSession(true);
        if (session.getAttribute("sheetData") != null)
            sheetData = (ArrayList) session.getAttribute("sheetData");

        Map<String, String> employeeCollectionMap = new LinkedHashMap<String, String>();
        Map<String, String> employeeMap = new LinkedHashMap<String, String>();


        for (int i = 0; i < sheetData.size(); i++) {
            List list = (List) sheetData.get(i);
            HSSFCell employeeid = (HSSFCell) list.get(0);
             HSSFCell employeeName = (HSSFCell) list.get(1);
            HSSFCell department = (HSSFCell) list.get(3);
            HSSFCell date = (HSSFCell) list.get(5);

                strdepartment = department.getRichStringCellValue().getString();
                if (!(employeeid.getRichStringCellValue().getString().equals("EmpID")|| date.getRichStringCellValue().getString().equals("Date")|| department.getRichStringCellValue().getString().equals("Department"))) {
                        if (!(strdepartment.equals("Temporary Card") || strdepartment.equals("Contractor"))) {
                              employeeCollectionMap.put(employeeid.getRichStringCellValue().getString() + "_" + j, date.getRichStringCellValue().getString());
                              if(!employeeMap.containsKey(employeeid.getRichStringCellValue().getString()))
                                    employeeMap.put(employeeid.getRichStringCellValue().getString(),employeeName.getRichStringCellValue().getString());
                            j++;
                            }
                        }

        }
        session.setAttribute("employeeCollectionMap", employeeCollectionMap);
        session.setAttribute("employeeMap", employeeMap);
    }

    protected void classifyEmployeesMapEntries(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession(true);
        Map<String, String> employeeCollectionMap = new LinkedHashMap<String, String>();
        if (session.getAttribute("employeeCollectionMap") != null)
            employeeCollectionMap = (Map) session.getAttribute("employeeCollectionMap");

        Map<String, Map<String, String>> employeeCollectionClassifiedMap = new HashMap<String, Map<String, String>>();
        List<String> employeeCollectionList = new ArrayList<String>();
        ;
        Iterator<String> oIterator = employeeCollectionMap.keySet().iterator();
        while (oIterator.hasNext()) {
            String sKey = oIterator.next();
            String sFirst = sKey.substring(0, sKey.indexOf("_"));
            if (!employeeCollectionList.contains(sFirst)) {
                employeeCollectionList.add(sFirst);
            }
        }
        for (String sKey : employeeCollectionList) {
            Map<String, String> oChildMap = new HashMap<String, String>();

            Iterator<String> oIterator2 = employeeCollectionMap.keySet().iterator();
            while (oIterator2.hasNext()) {
                String sChildKey = oIterator2.next();
                String sParentKey = sChildKey.substring(0,sChildKey.indexOf("_"));

                if (sKey.equals(sParentKey)) {
                    oChildMap.put(sChildKey,employeeCollectionMap.get(sChildKey));
                }
            }
            employeeCollectionClassifiedMap.put(sKey, oChildMap);
        }
        session.setAttribute("employeeCollectionClassifiedMap",employeeCollectionClassifiedMap);
        session.setAttribute("employeeCollectionList", employeeCollectionList);
    }

    @SuppressWarnings({ "static-access", "unused" })
    protected void prepareReport(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession(true);

        String startDate="",endDate="",delimiter = null, dateValues[] = null;
        int totalworkingdays = 0, tempWorkingDays = 0,year = 0,month=0,day=0,lastdayofmonth;

        String employeeName=null;

        Workindays workingdays = new Workindays();

        Map<String, Map<String, String>> employeeCollectionClassifiedMap = new HashMap<String, Map<String, String>>();
        ConcurrentHashMap<String, String> workingdayMap = new ConcurrentHashMap<String, String>();
        Map<String, String> employeeNameMap = new LinkedHashMap<String, String>();
        Map<String, String> reportMap = new LinkedHashMap<String, String>();
        ConcurrentHashMap<String,String> tempworkingDaysMap = new ConcurrentHashMap<String, String>();
        Map<String,String> employeeAbsentDateMap ;
        Map<String, String> fixedHolidayMap = new LinkedHashMap<String, String>();
        Map<String, String> employeeCollectionMap = new LinkedHashMap<String, String>();
        Map<String,Map<String,String>> employeeDateSuggestionMap =new  LinkedHashMap<String, Map<String,String>>();

        //if(request.getParameter("startdate")!=null)startDate =(String) request.getParameter("startdate");
        //if(request.getParameter("enddate")!=null)endDate =(String) request.getParameter("enddate");
        //System.out.println("Start Date : "+startDate+" : End Date : "+endDate);

        List<String> employeeCollectionList = new ArrayList<String>();
        List<String> employeeIDList = new ArrayList<String>(); 

        if (session.getAttribute("employeeCollectionList") != null)
            employeeCollectionList = (List) session.getAttribute("employeeCollectionList");
        if (session.getAttribute("employeeCollectionList") != null)
            employeeCollectionClassifiedMap = (Map) session.getAttribute("employeeCollectionClassifiedMap");
        if (session.getAttribute("employeeMap") != null)
            employeeNameMap = (Map) session.getAttribute("employeeMap");

        if (session.getAttribute("employeeCollectionMap") != null)
            employeeCollectionMap = (Map) session.getAttribute("employeeCollectionMap");

        // to get date from excel sheet
         Iterator<Map.Entry<String,String>> employeeCollectionIterator = employeeCollectionMap.entrySet().iterator();
        int i=0;
        do {
                Map.Entry<String,String> employeeEntry = employeeCollectionIterator.next();
                startDate = employeeEntry.getValue();
            }while(i<0);

        delimiter = "/";
        dateValues = startDate.split(delimiter);

        year = Integer.parseInt(dateValues[2]);
        month = Integer.parseInt(dateValues[1]);
        day = Integer.parseInt(dateValues[0]);

        lastdayofmonth = workingdays.getLastDay(year, month, day);
        String daystr="";
        String monthStr="";

        if(day<10)daystr="0";
        if(month<10)monthStr="0";
        endDate = daystr+lastdayofmonth+"/"+monthStr+month+"/"+year;

        System.out.println("workingMap is called");
        tempworkingDaysMap = workingdays.getWorkingDaysMap(year, month, day);
        System.out.println("tempworkingDaysMap : "+tempworkingDaysMap);

        //call Holiyday map
        System.out.println("getHolidaysMap is called");
        fixedHolidayMap = workingdays.getHolidaysMap(startDate, endDate);
        System.out.println("fixedHolidayMap : "+fixedHolidayMap);
        // remove the holidays from working days map
        workingdayMap = workingdays.removeHoliday(tempworkingDaysMap, fixedHolidayMap);
        System.out.println("workingdayMap : "+workingdayMap);
        totalworkingdays = workingdayMap.size();

        /*below code is not used since the start and end date are not from user request*/

        /*workingdayMap = workingdays.getWorkingDaysMap(startDate,endDate);
        totalworkingdays = workingdayMap.size(); */

        for (String employeeID : employeeCollectionList) {
            Map<String, String> employeeMap = employeeCollectionClassifiedMap.get(employeeID);
             if (employeeMap.size() < totalworkingdays) {
                        employeeAbsentDateMap =new LinkedHashMap<String,String>();
                        Iterator<Map.Entry<String,String>> holyDayiterator = workingdayMap.entrySet().iterator();

                     while (holyDayiterator.hasNext()) {
                            Map.Entry<String,String> holiDayEntry = holyDayiterator.next();
                            if(!employeeMap.containsValue((holiDayEntry.getValue()))) employeeAbsentDateMap.put(holiDayEntry.getValue().toString(), holiDayEntry.getValue().toString());
                        }

                if(workingdays.isEmployee(employeeID))//check if the employee id exist 
                     {
                         if ( !employeeIDList.contains(employeeID))  employeeIDList.add(employeeID);

                                 ConcurrentHashMap<String, String> employeeLeaveReportDateDBMap= workingdays.getLeaveReportMap(employeeID,startDate,endDate); 
                                 if(employeeLeaveReportDateDBMap.size()==0)
                                     {
                                         employeeDateSuggestionMap.put(employeeID, employeeAbsentDateMap);
                                     }
                                 else{
                                         ConcurrentHashMap<String,String> employeeDatesFormatedMap = workingdays.changeLeaveDataMapFormat(employeeLeaveReportDateDBMap);
                                         Map<String,String> employeeDatesMap=workingdays.removeLeaveAppliedDate(employeeDatesFormatedMap,employeeAbsentDateMap);
                                         employeeDateSuggestionMap.put(employeeID, employeeDatesMap);
                                   } 
                     }
                }
        }
        if(reportMap.size()>0) session.setAttribute("message", "Comparing access-card data with leave manager data is done ");
        else session.setAttribute("message", "Comparing access-card data with leave manager data is done no data exists");

        session.setAttribute("leaveMap",employeeDateSuggestionMap);
        session.setAttribute("employeeIDList",employeeIDList);
        session.setAttribute("employeeNameMap",employeeNameMap);

    }

    /* this method is not used */
    @SuppressWarnings("unchecked")
    protected void generateLeaveReport(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession(true);
        StringBuilder sb = new StringBuilder();
        String classname=null;
        int sno=1,style=0;
        Map<String, String> leavereportMap = new LinkedHashMap<String, String>();

        if (session.getAttribute("leaveMap") != null)
            leavereportMap = (Map) session.getAttribute("leaveMap");

        if (leavereportMap != null && leavereportMap.size() > 0) {
            Iterator<Map.Entry<String, String>> entries = leavereportMap.entrySet().iterator();
            sb.append("<TABLE ALIGN=\"CENTER\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"5\" >");
            while (entries.hasNext()) {
                Map.Entry<String, String> entry = entries.next();
               // System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
                if (style % 2 == 0) {
                    classname = "darkrow";
                } else {
                    classname = "lightrow";
                }
                    sb.append("<TR class=\"" + classname + "\">");
                        sb.append("<TD width=\"10%\" ALIGN=\"CENTER\" class='homelink'>"+sno+"</TD>");
                        sb.append("<TD width=\"35%\" ALIGN=\"CENTER\" class='homelink' style=\"line-height:15px;\">"+entry.getKey()+ "</TD>");
                        sb.append("<TD width=\"35%\" ALIGN=\"CENTER\" class='homelink' style=\"line-height:15px;\">"+entry.getValue()+ "</TD>");
                        sb.append("<TD width=\"35%\" ALIGN=\"CENTER\" class='homelink' style=\"line-height:15px;\">Send Mail</TD>");
                    sb.append("</TR>");
            sno++;
            style++;
             }
            sb.append("</TABLE>");
        }
        session.setAttribute("leaveReport",sb.toString());
    }
}

以前打印过,但现在没有打印出来,请帮我找到相同的内容。

此致 贝

1 个答案:

答案 0 :(得分:0)

重新启动服务器并检查是否重新启动系统本身。在这样做之后,请检查sop将被打印。