响应字符数据:
这行代码用来设置响应的数据格式,以及他的字符集(防止中文乱码)
响应字节数据:
@WebServlet("/resp4")
public class ResponseDemo4 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("resp2...");
// 输入流
FileInputStream fis = new FileInputStream("E:\\宝宝.jpg");
//输出流
ServletOutputStream out = response.getOutputStream();
//使用IOUtils工具类实现流copy
IOUtils.copy(fis,out);
fis.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}