Create a new window and direct it to your servlet url then onload.close();

Read jQuery HowTo Resource  -  http://jquery-howto.blogspot.com



On Thu, Jan 8, 2009 at 7:08 PM, ruquia <ruquiatabas...@gmail.com> wrote:
>
> Hi i am calling a servlet using JQuery and my servlets create an excel
> file at runtime and provides the option for the user to open save or
> cancel the file created
>
> JQuery code is
>
>         $.post("../reports/BillIDPropIDExcelExport",{csvstring: $
> ("#vname1").val(),count:$("#vname2").val(),propType:$("#vname3").val
> (),instValue:$("#vname4").val()},function(data){
>    alert(data);document.body.style.cursor="default"; });
>
>
>
> and my servlets that creates the file at runtime is
>
>  try
>            {
>                        HSSFWorkbook wb          = new HSSFWorkbook();
>                        HSSFSheet sheet = wb.createSheet("Customer Details 
> Connection
> Fee");
>
>                         HSSFDataFormat format = wb.createDataFormat();
>                         HSSFCellStyle cstyle;
>
>                         cstyle =  wb.createCellStyle();
>                         
> cstyle.setDataFormat(format.getFormat("#,###,###.00"));
>
>
>
>
>                        HSSFRow row     = sheet.createRow((short)0);
>                        HSSFCell c0=row.createCell((short)0);
>                        HSSFCell c1=row.createCell((short)1);
>                        HSSFCell c2=row.createCell((short)2);
>
>
>
>
>
>                        c0.setCellValue("CHAR_PREM_ID");
>                        c1.setCellValue("SA_TYPE_CD");
>                        c2.setCellValue("UOM_CD");
>
>
>
>                          c0.setCellStyle(style);
>                          c1.setCellStyle(style);
>                          c2.setCellStyle(style);
>
>
>
>
>                String acplotnumber="",finalcsvstring="",finalacplotnumber1="";
>
>                String csvstring=request.getParameter("csvstring");
>                System.out.println(csvstring);
>                String count=request.getParameter("count");
>                System.out.println(count);
>                String instValue1=request.getParameter("instValue");
>                String propType1=request.getParameter("propType");
>
>
>                if(propType1.length()==4)
>                    propType="'CONBASE','CONGROW'";
>            else
>                        propType="'"+propType1+"'";
>
>                d= new OracleDatabaseConnectionPROD();
>                connection=d.connect();
>                //System.out.println("OracleDatabaseConnectionPROD");
>
>
>
>         stmt = connection.createStatement();
>         connection.setAutoCommit(false);
>
>                {
>
>                rs=stmt.executeQuery("SELECT A.CHAR_PREM_ID, SA_TYPE_CD, 
> F.UOM_CD,
> C.BILL_ID, SUM(CALC_AMT) as CALC_AMOUNT from Customers");
>
>
>
>        while(rs.next())
>        {
>
>                String CHAR_PREM_ID=rs.getString(1);
>                String SA_TYPE_CD=rs.getString(2);
>                String UOM_CD=rs.getString(3);
>                String BILL_ID=rs.getString(4);
>                float CALC_AMOUNT=rs.getFloat(5);
>
>
>
>                            HSSFCellStyle style1 = wb.createCellStyle();
>                            HSSFFont font1 = wb.createFont();
>                            font1.setFontHeightInPoints((short)8);
>                            style1.setFont(font1);
>
>
>                            row     = sheet.createRow((short)j);
>
>                                // bold
>
>
>                                HSSFCell cell0 =row.createCell((short)0);
>                                HSSFCell cell1 =row.createCell((short)1);
>                                HSSFCell cell2 =row.createCell((short)2);
>
>                            cell0.setCellValue(CHAR_PREM_ID);
>                            cell1.setCellValue(SA_TYPE_CD);
>                            cell2.setCellValue(UOM_CD);
>
>
>
>                                cell0.setCellStyle(style1);
>                                cell1.setCellStyle(style1);
>
>
>
>                                j++;
>
>                        }
>                        //FileOutputStream fileOut = new FileOutputStream(fname
> +"ExtractBillID"+dateFormat+".xls");
>                        //wb.write(fileOut);
>                        //fileOut.close();
>                        String filename="ExtractBillID"+dateFormat+".xls";
>
>                         String contentType = 
> getServletContext().getMimeType(filename);
>                         System.out.println(contentType);
>                         BufferedInputStream in = null;
>                        try
>                        {
>
>                      //        in = new BufferedInputStream(getServletContext
> ().getResourceAsStream(fname+filename));
>                            response.setContentType(contentType);
>                            response.setHeader("Content-Disposition"," inline;
> filename=" + filename);
>
>                            ServletOutputStream sout = 
> response.getOutputStream();
>                            wb.write(sout);
>                            byte[] buffer = new byte[4 * 1024];
>
>                          //  int data;
>                          //  while((data = in.read(buffer)) != -1)
>                          //  {
>                             //   sout.write(buffer, 0, data);
>                          //  }
>                            sout.flush();
>                        }
>                        catch(Exception e)
>                        {
>                           e.printStackTrace();
>                           return;
>                        }
>                        finally
>                        {
>                            try
>                            {
>                        //        in.close();
>                            }
>                            catch(Exception ee)
>                            {
>                                ee.printStackTrace();
>                            }
>                        }
>
>
>
>
>                        connection.close();
>
> }
>
>
> catch(Exception e)
> {
>        //out.println("Error"+e.toString());
>        e.printStackTrace();
>
> }
>        }
> catch(Exception e)
> {
>        //out.println("Error"+e.toString());
>        e.printStackTrace();
>
>
> }
> finally
> {
>
>
>        //out.println("The Excel File Created Saved At P:\\DATA_LOAD As
> ExtractBillID"+dateFormat);
>
> }
>
>
>
>  }
>
>
>
> When i directly access the url i can get the open save an dcancel
> option and the servlet runs properly but when i am calling via jquery
> the open save and cancel option is not comming  can anybody suggest me
> how do i do this please
>
>

Reply via email to