1.OutputStream
Use steps: Get output stream set Chinese convert a string to a byte array call Outputstream.write ()
Here only the contents of the Doget method are posted:
protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException c2/>//gets OutputStream output stream
outputstream outputstream = Response.getoutputstream ();
Set Chinese
response.setheader ("Content-type", "Text/html;charset=utf-8");
String data = "Hello, here is the OutputStream way to the page output content";
Converts a character to an array of bytes and specifies the UTF-8 encoding
byte[] Databytearr = data.getbytes ("UTF-8"); output
outputstream.write (Databytearr);
}
2.PrintWriter
Using steps: Set document type and encoding to get getwriter () output
is also the content that only pastes the Doget method:
Set the response content type and encoding mode
response.setcontenttype ("Text/html;charset=utf-8");
PrintWriter out = Response.getwriter ();
Out.println ("Hello, here is the PrintWriter way to the page output");
3. Summary
The outputstream is output in bytes, and the PrintWriter is output in character form.
The difference between a byte stream and a character