ここと同じ方法で csv ダウンロードを実行しようとしています: How to provide a file download from a JSF backing Bean?
私の応答はnullPointerException
、output.write()
行に投げ続けます。Bean はリクエスト スコープです。ヌルポインタについて何か考えはありますか?
try
{
//submitForm();
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
response.reset();
response.setContentType("text/csv");
//response.setContentLength(contentLength);
response.setHeader ( "Content-disposition", "attachment; filename=\"Reporting-" +
new Date().getTime() + ".csv\"" );
OutputStream output = response.getOutputStream();
String s = "\"Project #\",\"Project Name\",\"Product Feature(s)\",";
s+="\"Project Status\",";
s+="\"Install Type\",";
s+="\"Beta Test\",\"Beta Test New/Updated\",";
s+="\"Production\",\"Production New/Updated\",";
s+="\n";
InputStream is = new ByteArrayInputStream( s.getBytes("UTF-8") );
int nextChar;
while ((nextChar = is.read()) != -1)
{
output.write(nextChar);
}
output.close();
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}