如果生成一个文本,只有一段话,像下面代码就可以了
- Java code
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html;charset=UTF-8");response.setCharacterEncoding("UTF-8");response.setHeader("Content-disposition", "attachment;filename=aa.txt" );byte[] aa="中国,你好".getBytes();OutputStream out=response.getOutputStream();out.write(aa);out.close();}
如果servlet中获得的是一个List<Student>的列表,Student中,包含id,name,age属性
那么遍历这个List<Student>中的数据,要怎样并放到byte[]数组中。数组的大小要如何确定?
如何将数据都全部写入byte[]数组中后,再向客户端输出.