如何在 Websphere Portal 上显示来自 Struts portlet 的 Excel 内容

发布于 2024-07-21 09:07:44 字数 1039 浏览 4 评论 0原文

这是代码,它不显示 .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,[email protected],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;
}
}

Here is the code, it don't display the .csv file:

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,[email protected],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;
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生死何惧 2024-07-28 09:07:44

关闭& 刷新输出流。

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

close & flush the output stream.

also check if the doVizualizare method is called

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文