首页 > 其他分享 >响应字符数据

响应字符数据

时间:2023-03-23 15:46:54浏览次数:40  
标签:字符 resp req HttpServletResponse 响应 Override 数据

响应字符数据:

@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

相关文章