Response writer output data

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.