使用字节流和字符流向浏览器输出数据
字符流:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExceptiom {
? ? ? ? ? ?//解決中文亂碼
? ? ? ? ? ?response.setContentType("text/html;charset=utf-8");
? ? ? ? ? ?PrintWriter writer = response.getWriter();
? ? ? ? ? ?String dataString = "中文";
? ? ? ? ? ?// 發送數據
? ? ? ? ? ?writer.write(dataString);
}
?
?
// 字節流
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExceptiom {
? ? ? ? ? ?//指定瀏覽器以xx編碼格式解析請求返回的數據
? ? ? ? ? ?response.setContentType("text/html;charset=utf-8");
? ? ? ? ? ?ServletOutputStream stream = response.getOutputStream();
? ? ? ? ? ?String dataString = "中文";
? ? ? ? ? ?// 發送數據
? ? ? ? ? ?stream .write(dataString.getBytes("utf-8"));
}
總結
以上是生活随笔為你收集整理的使用字节流和字符流向浏览器输出数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 使用 HTTP 访问网络
- 下一篇: 南邮ctf nctf CG-CTF we