标签:style blog http java color 使用
1 package cn.itcast.response; 2 3 import java.io.IOException; 4 import java.io.OutputStream; 5 import java.io.PrintWriter; 6 import java.io.UnsupportedEncodingException; 7 8 import javax.servlet.ServletException; 9 import javax.servlet.http.HttpServlet; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 13 //通过Response的writer留输出数据的问题 14 public class ResponseDemo extends HttpServlet { 15 16 public void doGet(HttpServletRequest request, HttpServletResponse response) 17 throws ServletException, IOException { 18 19 test1(response); 20 } 21 22 private void test2(HttpServletResponse response) throws IOException { 23 //设置response使用的码表,以控制response以什么码表向浏览器写出数据。 24 response.setCharacterEncoding("UTF-8"); 25 26 //指定浏览器以什么码表打开服务器发送数据。 27 response.setContentType("text/html;charset=utf-8"); 28 29 String data="中国"; 30 31 PrintWriter pw = response.getWriter(); 32 pw.write(data); 33 } 34 35 private void test1(HttpServletResponse response) throws IOException { 36 //设置response使用的码表,以控制response以什么码表向浏览器写出数据。 37 response.setCharacterEncoding("UTF-8"); 38 39 //指定浏览器以什么码表打开服务器发送数据。 40 response.setHeader("Content-type", "text/html;charset=utf-8"); 41 42 String data="中国"; 43 44 PrintWriter pw = response.getWriter(); 45 pw.write(data); 46 } 47 48 public void doPost(HttpServletRequest request, HttpServletResponse response) 49 throws ServletException, IOException { 50 51 } 52 53 }
response的Writer输出数据的问题,布布扣,bubuko.com
标签:style blog http java color 使用
原文地址:http://www.cnblogs.com/aineko/p/3818993.html