Response响应字符数据
//text/html解码html,charset解码汉字
response.setContentType("text/html;charset=utf-8");
//1、获取字符输入流
PrintWriter writer = response.getWriter();
writer.write("你好");
writer.write("<h1>124</h1>");
响应字节数据
添加一个io工具(在servlet中添加)
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
/* * * 获取字节数据 * * */ //1、读取文件 FileInputStream fis = new FileInputStream("e://applebox.jpg"); //2、获取response字节输出流 ServletOutputStream os = response.getOutputStream(); //完成流的copy IOUtils.copy(fis,os); fis.close();