/**
* 查看附件
*/
public
String view() {
try
{
Attachment newAttach = attachService.getAttachment(attach.getId());
if
(attach != null ) {
try
{
InputStream inStream = new
FileInputStream(newAttach
.getFilePath());
this .getResponse().reset();
this .getResponse().setContentType( "bin" );
this .getResponse().addHeader(
"Content-Disposition" ,
"attachment; filename=\""
+ URLEncoder.encode(newAttach.getName(),
"UTF-8" ).replace( "+" , "%20" ) + "\"" );
// 循环取出流中的数据
byte [] b = new
byte [ 512 ];
int
len;
this .getResponse().getOutputStream().flush();
while
((len = inStream.read(b)) > 0 ) {
this .getResponse().getOutputStream().write(b, 0 , len);
}
inStream.close();
} catch
(FileNotFoundException e) {
//e.printStackTrace();
this .sendMessage( "error" );
} catch
(IOException e) {
this .sendMessage( "error" );
//e.printStackTrace();
}
}
} catch
(DAOException e) {
e.printStackTrace();
this .addActionMessage(e.getMessage());
return
ERROR;
}
return
null ;
}
|