1

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,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;
}
}
trunkc
  • 6,223
  • 4
  • 34
  • 49
DFG
  • 2,217
  • 3
  • 22
  • 24

1 Answers1

0

close & flush the output stream.

also check if the doVizualizare method is called

Salandur
  • 6,409
  • 2
  • 22
  • 23