响应字符数据:
@WebServlet("/servletDemo3") public class HttpServletDemo3 extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //设置响应编码格式 resp.setContentType("text/html;charset=UTF-8"); //获取字节输出流 ServletOutputStream os = resp.getOutputStream(); //写数据 os.write("你好".getBytes("UTF-8")); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } }
响应图片:
标签:字符,resp,req,HttpServletResponse,响应,Override,数据 From: https://www.cnblogs.com/weiduaini/p/17247680.html