开发者

jsf 1.1 save as box problem

I am using JSF 1.1 on Tomcat 6.0.26 and Java 1.4 version. I have to use them in my project. My jsf page has a datatable and I want them to export but with save as box. After I click export excel commandlink it shows browser like this:

ÐÏࡱá;þÿ þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿRoot Entryÿÿÿÿÿÿÿÿ@ Workbookÿÿÿÿÿÿÿÿÿÿÿÿ0 ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÓÌAá°Áâ\pmusty B°a=œ¯¼=h\:¾#8X@"·Ú1ÈÿArial1ÈÿArial1ÈÿArial1ÈÿArial"$"#,##0_);("$"#,##0)!"$"#,##0_);[Red]("$"#,##0)""$"#,##0.00_);("$"#,##0.00)'""$"#,##0.00_);[Red]("$"#,##0.00)7*2_("$"* #,##0_);_("$"* (#,##0);_("$"* "-");(@).))(* #,##0_);_(* (#,##0);_(* "-");(@)?,:("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??);(@)6+1(* #,##0.00_);_(* (#,##0.00);_(* "-"??);(@_)àõÿ À àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ à À à+õÿ øÀ à)õÿ øÀ à,õÿ øÀ à*õÿ øÀ à õÿ øÀ “€ÿ“€ÿ“€ÿ“€ÿ“€ÿ“€ÿ`…-Sheet0Œü¿ADSOYAD DEPARTMANEVCEPDAHILIerdemaktasYonetici02mesutozenIT03mustafaaydemir Netweaver01yunustastutanDeneme0506004ÿT‘IΆ » ÌÁ dü©ñÒMbP?_*+‚€%ÿÁƒ„¡"d,,à?à?Uý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ý ÿÿÿÿÿ>¶@ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ !"#$þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ开发者_开发问答ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

How can I solve this?

thnx balusC. But problem not solved. here is my code..

`public String export(List list) {

    Iterator i1 = list.iterator();
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet s = wb.createSheet();
    HSSFRow r = null;
    HSSFCell c = null;
    int i = 0;

    try {

        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        HttpServletResponse resp = (HttpServletResponse) externalContext
                .getResponse();
        ServletOutputStream out = resp.getOutputStream();
        resp.setContentType("application/vnd.ms-excel");


        HSSFRow r2 = s.createRow(0);

        for (short cellnum = (short) 0; cellnum < 6; cellnum++) {

            c = r2.createCell(cellnum);

            if (cellnum == 0)
                c.setCellValue("AD");
            else if (cellnum == 1)
                c.setCellValue("SOYAD");
            else if (cellnum == 2)
                c.setCellValue("DEPARTMAN");
            else if (cellnum == 3)
                c.setCellValue("EV");
            else if (cellnum == 4)
                c.setCellValue("CEP");

            else if (cellnum == 5)
                c.setCellValue("DAHILI");
        }


        while (i1.hasNext()) {
            md1 = new Model();
            md1 = (Model) i1.next();

            int rownum = i + 1;

            r2 = s.createRow(rownum);

            for (short cellnum = (short) 0; cellnum < 6; cellnum++) {

                c = r2.createCell(cellnum);

                if (cellnum == 0)
                    c.setCellValue(md1.getAd());
                else if (cellnum == 1)
                    c.setCellValue(md1.getSoyad());
                else if (cellnum == 2)
                    c.setCellValue(md1.getDepartman());
                else if (cellnum == 3)
                    c.setCellValue(md1.getEv());
                else if (cellnum == 4)
                    c.setCellValue(md1.getCep());

                else if (cellnum == 5)
                    c.setCellValue(md1.getDahili());

            }

            i++;
        }
        resp.setHeader("content-disposition:",
                "attachment; filename= \"TelefonRehberi.xls\"");

        wb.write(out);
        out.flush();
        out.close();

        facesContext.responseComplete();
    } catch (Exception e) {
        System.out.println("Error: " + e);
    }

    return "";
}`


You need to set the content type header so that the browser understands what kind of file it is.

response.setHeader("Content-Type", "application/vnd.ms-excel");

You need to set the content disposition header so that the browser pops a Save as dialog:

response.setHeader("Content-Disposition", "attachment;filename=\"" + yourFileName + "\"");

You need to ensure that you write the file as binary data, not as character data.

InputStream input = getExcelFileContentSomehow();
OutputStream output = response.getOutputStream();
// Write input to output.

Update: as per your code snippet, your Content-Disposition header is incorrect. There's a colon at end of header name. Remove it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜