原因查出来了,通过对比两个生成的文件知道原因了(一个在本地生成,一个下载另存为),本地生成的完整的文件结束码流:
---------------------------------------------------------------

%F end
---------------------------------------------------------------下载下来的损坏的文件结束码流:---------------------------------------------------------------

%F end<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="http://localhost:8080/archive/"> <title>My JSF 'showDocument.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--></head>
  
<body>

<form id="_id0" method="post" action="/archive/showDocument.faces;jsessionid=1AF05A541C564812C3DA33D1D3224273" enctype="application/x-www-form-urlencoded">  
 
 
 
 <table>
<tbody>
<tr>
<td><a href="#" target="blank" onclick="document.forms['_id0']['_id0:_idcl'].value='_id0:_id2';document.forms['_id0']['documentID'].value='2'; document.forms['_id0'].submit(); return false;">浏览附件</a></td>
</tr>
</tbody>
</table> <input type="hidden" name="_id0" value="_id0" /><input type="hidden" name="_id0:_idcl" /><input type="hidden" name="documentID" /></form>

</body>
</html>---------------------------------------------------------------
损坏的文件比完整的文件多了一段网页,猜测是输出流没有完全关闭,结果还是接续输出。可是已经掉用了out.close了呀。思考:
从JSF的生命周期来看,执行这个<h:commandLink>的action方法的时候应该在调用应用阶段,初步估计JSF自动在最后的呈现响应阶段有重新打开了输出流,在原来的OutputStream上继续输出了网页代码。尝试解决:
把上面那段输出代码放到一个jsp页面试一试。不知道行不行。大家来支招啊。