1. All are inherited from the java. Io. Writer class.
Jspwriter can directly use the out object output on the JSP page. You can use pagecontext. getout (); to obtain the jspwriter object.
Printwrietr must use response. getwriter () in the JSP page to obtain its object. The two have different scopes.
2. Call two methods to output data to the page at the same time on the JSP page. The data in printwriter is output before jspwriter.
For example:
Jspwriter out1 = pagecontext. getout (); // you can directly use the out object on the JSP page instead
Example: Use pagecontext. getout (); to obtain the jspwriter object. In this way, out1 is the same as the out object encapsulated in the JSP page.
An object. (You can use out = out1 to determine whether two objects are equal .)
Out1.print ("222 ");
Printwriter PW = response. getwriter ();
PW. Print ("111 ");
* In this case, "111" is displayed on the browser, and "222" is displayed. It indicates that no matter whether jspwriter and printwriter areProgramHow is the order in?The data in pringwriter is always output first and then the data in jspwriter is output. This is because the out object is equivalent to inserting it into the buffer zone before printwriter.When an out object meets certain conditions, the print () method of the printwriter object is called to output the content in the out buffer to the browser.CodeThe output can be written as follows:
Spwriter out1 = pagecontext. getout ();
Out1.print ("222 ");
Out1.flush (); // refresh the buffer
Printwriter PW = response. getwriter ();
PW. Print ("111 ");
* Conditions for the out object to call the print () method of the printwriter object to output content in the buffer:
^ Set the buffer attribute of the page command to disable the cache function of the out object.
^ The content written to the out object is filled with the buffer of the out object
^ The entire JSP page ends.