hi everybody,
I have one doubt ,
In my servlet there is a code to display
day of the week,but it displaying from sunday-satday.
But for me I have to display from Mon-Sunday.
can any one suggest me how to change the day.

Date dnow = new java.util.Date();

            int iMonth = Integer.parseInt(DateEx.dateToStringFormat(dnow,"MM"));
            int iYear = Integer.parseInt(DateEx.dateToStringFormat(dnow,"YYYY"));
            int iDay = Integer.parseInt(DateEx.dateToStringFormat(dnow,"DD"));
            int iWeek = 0;

            Calendar cWeek = Calendar.getInstance();
            if (request.getParameter("cweek") != null) {
                iWeek = Integer.parseInt(request.getParameter("cweek"));
            } else {
                cWeek.set(iYear, iMonth+1, iDay);
                iWeek = cWeek.get(cWeek.WEEK_OF_MONTH);
                cWeek.set(iYear, iMonth+1, 1);
                if (cWeek.get(cWeek.DAY_OF_WEEK) != 1) {
                    iWeek = iWeek - 1;
            }
            }
            if (iWeek==0)
                iWeek=1;

            String strMonth = null;
            String strYear = null;
            String strFP = null;
            Date dFDay = null;
            Date dLDay = null;
            Date dend = null;
            int curYear = 0;
            int curMonth = 0;
            int iSDate = 1;
            int iFDate = 1;

            ArrayList[] aL = new ArrayList[32];

            try {
                if (page.get("query") != null) {    //Search
                    curMonth = Integer.parseInt(page.get("sMonth"));
                    curYear = Integer.parseInt(page.get("sYear"));
                    iWeek=1;

                    scheduleDet = new FPSScheduleDetail();
                    if (page.get("FPCode") != null) {
                        scheduleDet.sFPCode = page.get("FPCode");
                    } else {
                        if (request.getParameter("fpcode") != null)
                            scheduleDet.sFPCode = request.getParameter("fpcode");
                    }
                } else {
                    if (request.getParameter("cyear") != null) {
                        curYear = Integer.parseInt(request.getParameter("cyear"));
                    } else {
                        curYear = iYear;
                    }

                    if (request.getParameter("cmonth") != null) {
                        curMonth = Integer.parseInt(request.getParameter("cmonth"));
                    } else {
                        curMonth = iMonth;
                    }
                    scheduleDet = new FPSScheduleDetail();
                    scheduleDet.sFPCode = page.get("FPCode");

                    if (request.getParameter("fpcode") != null)
                        scheduleDet.sFPCode = request.getParameter("fpcode");
                }

        if (iWeek != 0){
                    //scheduleDet = new FPSScheduleDetail();
                    //scheduleDet.sFPCode = page.get("FPCode");

                    if (scheduleDet.sFPCode == null)
                        scheduleDet.sFPCode = secu.getFpCode();

                    //if (request.getParameter("fpcode") != null)
                    //  scheduleDet.sFPCode = request.getParameter("fpcode");

                    strMonth = Integer.toString(curMonth);
                    strYear = Integer.toString(curYear);
                    iYear = curYear;
                    iMonth = curMonth;

                    dend = DateEx.endMonthDate(iYear,iMonth);

                    Calendar cDay = Calendar.getInstance();

                    for (int i = 1; i < 32; i++) {
                        cDay.set(iYear, iMonth - 1, i);
                        if (cDay.get(cDay.DAY_OF_WEEK) == 1) {
                            iSDate = i;
                            iFDate = i;
                            break;
                        }
                    }
                    iSDate = 1;
                    iFDate = 1;
                    iSDate = iSDate + ((iWeek - 1) * 7);
                    
                    cDay.set(iYear, iMonth-1, iSDate);
                    cDay.add(cDay.DATE, +7);

                    dFDay = DateEx.stringToDateTime(Integer.toString(iSDate) + "/" + strMonth + "/" + strYear + " 00:00");
                    dLDay = DateEx.stringToDateTime(cDay.get(cDay.DATE) + "/" + (cDay.get(cDay.MONTH)+1) + "/" + cDay.get(cDay.YEAR) + " 00:00");

                }
                
            } catch(Exception ex) {
                page.writeErr(ex);
            }

            page.print("<TABLE><TR>");
            page.print("<TD CLASS='xtd'>Submenu : > </TD>");
            //page.print("<TD CLASS='xtd'><A HREF='wschdlr?miid=" + miid + "'> Weekly Schedule </TD>");
            page.print("<TD CLASS='xtd'><A HREF='mschdlr?miid=" + miid + "&fpcode=" + scheduleDet.sFPCode +"'> Monthly Schedule </TD>");
            page.print("</TR></TABLE>");
            page.print("<BR>");

            page.print("<FORM name='Schedule' action='wschdlr' method=POST>");

            RefCodeInfo[] refInfo = null;
            RefCodeInfo[] apptInfo = bizRef.getAPPT(sLang);
            if (request.getParameter("midd") != null) {
                miid = request.getParameter("midd");
            }

            if (miid.equalsIgnoreCase(pageid[0])) {
                refInfo = new RefCodeInfo[1];
                refInfo[0] = new RefCodeInfo();
                refInfo[0].sRefCode = secu.getFpCode();
                refInfo[0].sRefCodeDesc = refInfo[0].sRefCode + " - " + dbFP.getFPName(refInfo[0].sRefCode);
            } else if (miid.equalsIgnoreCase(pageid[1])) {
                FPStructureInfo[] stucInfo = dbFP.getFPDownline(secu.getFpCode());
                if (stucInfo != null) {
                    refInfo = new RefCodeInfo[stucInfo.length + 1];
                    for (int i = 0; i <= stucInfo.length; i++) {
                        refInfo[i] = new RefCodeInfo();
                        if (i == 0) {
                            refInfo[i].sRefCode = secu.getFpCode();
                            refInfo[i].sRefCodeDesc = refInfo[i].sRefCode + " - " + dbFP.getFPName(refInfo[i].sRefCode);
                            continue;
                        }
                        refInfo[i].sRefCode = stucInfo[i - 1].sFPCode;
                        refInfo[i].sRefCodeDesc = stucInfo[i - 1].sFPCode + " - " + dbFP.getFPName(stucInfo[i - 1].sFPCode);
                    }
                }
            } else if (miid.equalsIgnoreCase(pageid[2])) {
                FinancialPlannerInfo[] fpInfo = dbFP.getAllFP();
                if (fpInfo != null) {
                    refInfo = new RefCodeInfo[fpInfo.length];
                    for (int i = 0; i < fpInfo.length; i++) {
                        refInfo[i] = new RefCodeInfo();
                        refInfo[i].sRefCode = fpInfo[i].sFPCode;
                        refInfo[i].sRefCodeDesc = fpInfo[i].sFPCode + " - " + fpInfo[i].sFPName;
                    }
                }
            }

            page.print("<TABLE><TR>");
            page.print("<TD CLASS='xtd'>" + dbutil.getLabel(conmgr.env.getUserId(), "FPSSCHEDULE.FPCODE") + "</TD>");
            page.print("<TD CLASS='xtd'>" + htmlutil.printDropDownRefCode("FPCode", refInfo, scheduleDet.sFPCode, true, false, true, true, false) + "&nbsp &nbsp</TD>");
            page.print("<TD CLASS='xtd'>" + dbutil.getLabel(conmgr.env.getUserId(), "ENQUIRY.YEAR") + "</TD>");
            page.print("<TD CLASS='xtd'>" + htmlutil.printTextBox("sYear", Integer.toString(iYear), 4, 4) + "&nbsp </TD>");
            page.print("<TD CLASS='xtd'>" + dbutil.getLabel(conmgr.env.getUserId(), "ENQUIRY.MONTH") + "</TD>");

            //page.print("<TD CLASS='xtd'>" + htmlutil.printTextBox("sMonth", Integer.toString(iMonth), 2, 2) + "&nbsp </TD>");

            RefCodeInfo[] refMonth = null;
            refMonth = new RefCodeInfo[12];
            String sLM = null;
            sLM = Integer.toString(iMonth);

            if (sLM.length() == 1)
                sLM = "0" + sLM;

            page.print("<TD CLASS='xtd'>" + html.printDropDownMonth("sMonth", refMonth, sLM, true, false, false, true, true) + "&nbsp </TD>");
            page.print("<TD CLASS='xtd'><INPUT TYPE=SUBMIT NAME='query' VALUE=" + dbutil.getLabelOnly(conmgr.env.getUserId(), "B_ENQUIRY") + "> &nbsp&nbsp" + dbutil.getLabel(conmgr.env.getUserId(), "FPSSCHEDULE.WEEK") + " &nbsp</TD>");

            if (scheduleDet.sFPCode == null) {
                strFP = request.getParameter("fpcode");
            } else {
                strFP = scheduleDet.sFPCode;
            }

            iFDate = iFDate + (4 * 7);
            int daysinMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            if (((iYear % 4) == 0) && (((iYear % 100) != 0) || ((iYear % 400) == 0)))
                daysinMonth[1] = 29;

            for (int i = 1; i < 6; i++) {
                page.print("<TD CLASS='xtd'>");

                if (i==5 && iFDate > daysinMonth[iMonth - 1]) {

                } else {
                    if (i != iWeek) {
                        page.print("<TD CLASS='xtd'><A HREF='wschdlr?cmonth="+ curMonth + "&cyear=" + curYear + "&cweek=" + i + "&miid=" + miid +"&fpcode=" + strFP +"'>" + i + "</A></TD>");
                    } else {
                        page.print("<TD CLASS='xtd'>" + i + "</TD>");
                    }
                }
                page.print("</TD>");
            }

            page.print("</TR></TABLE>");
            page.print(html.printHiddenField("miid", miid));
            page.print(html.printHiddenField("fpcode", scheduleDet.sFPCode));
            page.print("</FORM>");

        schdDet = dbSchedule.getScheduleByFP(strFP, dFDay, dLDay);

            int iACount = Integer.parseInt(DateEx.dateToStringFormat(dFDay,"DD"));
            int iDate = 0;

            for (int i2 = 0; i2 < 32; i2++) {
            if(aL[i2] == null)
                aL[i2] = new ArrayList();
            }

            if (schdDet != null) {
                for (int i = 0; i < schdDet.length; i++) {
                    //for (int i2 = iACount; i2 < iACount + 7; i2++) {
                    for (int i2 = 1; i2 < 32; i2++) {
                        Calendar cl = Calendar.getInstance();
                        cl.setTime(schdDet[i].dtApptDateTime);
                        iDate = cl.get(Calendar.DAY_OF_MONTH);

                        if(iDate == i2) {
                            aL[i2].add(schdDet[i]);
                        }
                    }
                }
            }

            //show calendar

            SimpleDateFormat sd1 = new SimpleDateFormat("MMMMM");

            page.print("<CENTER>");
            page.print("<FORM NAME='fweek' ACTION='wschdlr' METHOD=POST>");
            page.print("<TABLE CELLPADDING='3' CELLSPACING='0' WIDTH='95%' BORDER='2' BGCOLOR='FFFFFF'>");
            page.print("<TR VALIGN='MIDDLE' ALIGN='CENTER'>");
            page.print("<TD COLSPAN='7'>");
            page.print("<TABLE CELLPADDING='0' CELLSPACING='0' WIDTH='100%' BORDER='0'>");
            page.print("<TR VALIGN='MIDDLE' ALIGN='CENTER'>");
            page.print("<TH WIDTH='100%' CLASS='xtd2'>" + dbutil.getLabel(conmgr.env.getUserId(), "FPSSCHEDULE.WEEK") + " " + iWeek + "&nbsp &nbsp" + sd1.format(dend) + " " + curYear + "</TH>");
            page.print("</TR></TABLE></TD></TR>");

            //start print details

            page.print("<TR VALIGN='TOP' ALIGN='CENTER' BGCOLOR='FFFFFF'>");

            SimpleDateFormat sd = new SimpleDateFormat("EEEEE");
            Calendar c = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();

            for (int iDay2 = 1; iDay2 < 8; iDay2++) {
                //c.set(Calendar.DAY_OF_WEEK,iDay2);
                c.set(c.get(c.YEAR), dend.getMonth(), iDay2);
                page.print("<TD WIDTH='14%' CLASS='xtd'>"+ sd.format(c.getTime()) + "<BR>");

                c2.set(iYear, iMonth-1, Integer.parseInt(DateEx.dateToStringFormat(dFDay,"DD")));
                c2.add(c2.DATE, + (iDay2-1));

                //page.print("(" + c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) + ")" + "</TH>");
                //page.print("<A HREF='feschdlr?miid=11005&mode=2&reload=&ApptDate="+ c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) +"&FPCode="+ strFP +"'>" + "(" + c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) + ")" + "</A></TD>");
                page.print("<A HREF='feschdlr?miid=11005&ApptDate="+ c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) +"'>" + "(" + c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) + ")" + "</A></TD>");
            }
            page.print("</TR>");

            int iC1 = 0;
            int iC2 = 0;

            for (int iC=iACount; iC < iACount + 7; iC++) {
                page.print("<TD WIDTH='14%' HEIGHT='100' VALIGN='TOP' ALIGN='LEFT' CLASS='xtd'><BR>");
                page.print("<TABLE CELLPADDING='0' CELLSPACING='0' WIDTH='100%' BORDER='0' BGCOLOR='FFFFFF'>");

                if (iC > daysinMonth[iMonth - 1]) {
                    iC2 = iC2 + 1;
                    iC1 = iC2;
                } else {
                    iC1 = iC;
                }

                if (! aL[iC1].isEmpty()) {
                    for (int iSDet=0; iSDet < aL[iC1].size(); iSDet++) {
                        FPSScheduleDetail a = (FPSScheduleDetail)aL[iC1].get(iSDet);

                        page.print("<TR>");
                        //page.print("<TD CLASS='xtd3'><A HREF='feschdlr?miid=11005&mode=2&ApptId="+ a.sApptId +"'>" + "<BR>" + DateEx.dateToStringFormat(a.dtApptDateTime,"HH:NN") + "<BR>" + dbClient.getClientName(a.sClientNo) + "<BR>" + a.sApptCode + "</A></TD>");

                        page.print("<TD CLASS='xtd3'><A HREF='feschdlr?miid=11005&mode=2&ApptId="+ a.sApptId +"'>");
                        page.print("<FONT SIZE='5'>" + DateEx.dateToStringFormat(a.dtApptDateTime,"HH:NN") + " - " + DateEx.dateToStringFormat(a.dtApptDateEnd,"HH:NN") + "</FONT>");

                        if (cv.isMandatory(a.sClientNo))
                            page.print("<BR>" + dbClient.getClientName(a.sClientNo) + "<BR>" + LookUpUtil.codeToDesc(apptInfo, a.sApptCode));
                        else
                            page.print("<BR> NOT ASSIGN <BR>" + LookUpUtil.codeToDesc(apptInfo, a.sApptCode));

                        if (a.sRstDesc != null)
                            page.print("<BR>" + a.sRstDesc + "<BR>");

                        if (a.sRemarks != null)
                            page.print("<BR>" + a.sRemarks + "<BR>");

                            page.print("<BR><BR><BR><BR></A></TD></TR>");
                    }
                }
                page.print("</TABLE>");
                page.print("</TD>");
            }

            page.print(html.printHiddenField("miid", miid));
            page.print("</TABLE></FORM>");
            page.print("</CENTER>");

and also in dropdownlist it showing same month twice

What an old book/resources you using???
Didn't see anybody for long time to write JSP as you page.print("<TABLE><TR>"); , also many methods and some Date constructors has been deprecated and are not used any more. I would recommend to use Calendar or even better GregorianCalendar. If you have instalation of tomcat in JSP examples you can find Date example or can check it here, also there is nice tutorial site with examples on how to date and time

hi,
thanks for your suggestion, but i wrote all this code in a servlet,
i.e (.java)file, sorry I forget to mention.

Well, this code is fairly bad, I'm sorry, I don't mean to be offensive, I'm just stating the way it is, but for a quick fix try this.

You are currently doing this

for (int iDay2 = 1; iDay2 < 8; iDay2++) {

which is essentially cycling through an array of days organized as

{ Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY }

So, think about it. What do you need to do to change the order of days you are interested in?

Setup an array in the order you want it (the days should still be in the proper order of course) and use that array in the for loop.

Like this:

int[] days = { Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY };
for (int dayIndex = 0; dayIndex < days.length; dayIndex++) {
    int iDay2 = days[dayIndex];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.