English 中文(简体)
Export file : faces Servlet threw java.lang.IllegalStateException: 在做出回应后无法取得进展
原标题:Export File : Faces Servlet threw java.lang.IllegalStateException: Cannot forward after response has been committed
  • 时间:2011-11-10 10:55:23
  •  标签:
  • jsf

我采用了一种出口xls文档的方法。 这种方法是正确的,但在被迫害后,我就得了。

面对: 在做出回应后无法取得进展

Here is the method:

public String exportXls() {
    OutputStream out = null;
    try {
        FacesContext cxt = FacesContext.getCurrentInstance();
        ExternalContext context = cxt.getExternalContext();
        HttpServletResponse response = (HttpServletResponse) context.getResponse();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=name.xls");
        out = response.getOutputStream();

        WritableWorkbook workbook = createWorkbook(response);

        // All sheets and cells added. Now write out the workbook
        workbook.write();
        workbook.close(); 
        System.out.println("XLS written!");
    } catch(Exception ex) {
        logger.error("ERROR OCCURRED WITH exportXls" + ex.toString());
    } finally {
        try {
            if (out != null) out.close();
        } catch(IOException e) {
            logger.error(e);
            e.printStackTrace();
        }
    }
    return "page";
}

页: 1 你们认为什么是问题?

最佳回答
问题回答

You cannot forward (or redirect) once there s been content output to the client.

你重新尝试做些什么,相当于为单一申请获得两项回复,或翻一番,但不是两页。





相关问题
JSF a4j:support with h:selectManyCheckbox

I m having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 ...

Mojarra for JSF Encoding

Can anyone teach me how to use mojarra to encode my JSF files. I downloaded mojarra and expected some kind of jar but what i had downloaded was a folder of files i don t know what to do with

如何拦截要求终止?

在共同基金中,如果用户要求终止,就需要采取一些行动。 我需要某种拦截器,但我不知道如何这样做。 我需要帮助。 增 编

ICEFaces inputFile getting the file content without upload

Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

How to correctly use ResultSet with h:dataTable

The problem is, that after displaying the ResultSet with <h:dataTable>, the connection is left open. If I close it, it closes the ResultSet too. I m thinking about copying the ResultSet data ...

热门标签