servlet向客户端生成文件并下载
如果生成一个文本,只有一段话,像下面代码就可以了
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();}