如何在 Websphere Portal 上显示来自 Struts portlet 的 Excel 内容
这是代码,它不显示 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关闭& 刷新输出流。
还要检查 doVizualizare 方法是否被调用
close & flush the output stream.
also check if the doVizualizare method is called