已搞定,下面是代码(写在servlet中):
ServletOutputStream out;
response.setHeader("Content-disposition", "attachment;filename="
+ java.net.URLEncoder.encode("a.txt","UTF-8"));
response.setContentType("application/vnd.ms-excel");
out = response.getOutputStream();
byte[] b=new byte[100];
String s="ssss";
try {
out.write(s.getBytes());
} catch (IOException e) {
e.printStackTrace();
}