1

这是代码,它不显示 .csv 文件:

public class ForwardAction extends MultiAction {
private static final String FILE_ERROR = "<h3><center>INVALID FILE</center></h3>";
    public ActionForward doVizualizare(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    StringBuffer sb = new StringBuffer();
    sb.append("Name,Email,Phone");
    sb.append(System.getProperty("line.separator"));
    sb.append("Naveen,naveen@ibm.com,111-111-111");

    OutputStream resOut = response.getOutputStream();
    try {
        response.setContentType("application/octet-stream"); 
        response.setHeader("Content-Disposition", "attachment; filename=\"a.csv\"");
        resOut.write(sb.toString().getBytes());
    } catch (Exception e) {
        resOut.write(FILE_ERROR.getBytes());
    }
    return null;
}
}
4

1 回答 1

0

关闭并刷新输出流。

还要检查是否调用了 doVizualizare 方法

于 2009-05-27T13:02:40.877 回答