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 // Issue 14 public class re Eclipsedemo 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 (Response response) throws ioexception {23 // set the code table used by response to control the code table in which response writes data to the browser. 24 response. setcharacterencoding ("UTF-8"); 25 26 // specify the code table in which the browser opens the server to send data. 27 response. setcontenttype ("text/html; charset = UTF-8"); 28 29 string data = "China"; 30 31 printwriter PW = response. getwriter (); 32 PW. write (data); 33} 34 35 private void test1 (httpservletresponse response) throws ioexception {36 // set the code table used by response to control the code table in which response writes data to the browser. 37 Response. setcharacterencoding ("UTF-8"); 38 39 // specify the code table in which the browser opens the server to send data. 40 response. setheader ("Content-Type", "text/html; charset = UTF-8"); 41 42 string data = "China"; 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}View code