response的Writer输出数据的问题

 package cn.itcast.response;

 import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; //通过Response的writer留输出数据的问题
public class ResponseDemo extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { test1(response);
} private void test2(HttpServletResponse response) throws IOException {
//设置response使用的码表,以控制response以什么码表向浏览器写出数据。
response.setCharacterEncoding("UTF-8"); //指定浏览器以什么码表打开服务器发送数据。
response.setContentType("text/html;charset=utf-8"); String data="中国"; PrintWriter pw = response.getWriter();
pw.write(data);
} private void test1(HttpServletResponse response) throws IOException {
//设置response使用的码表,以控制response以什么码表向浏览器写出数据。
response.setCharacterEncoding("UTF-8"); //指定浏览器以什么码表打开服务器发送数据。
response.setHeader("Content-type", "text/html;charset=utf-8"); String data="中国"; PrintWriter pw = response.getWriter();
pw.write(data);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { } }
上一篇:vscode配置phpxdebug


下一篇:response的outputStream输出数据的问题