This time I will show you how to use the servlet output of Ajax technology. What are the precautions when using Ajax technology servlet output. The following is a practical case, let's take a look.
When the Ajax server uses PrintWriter out=resp.getWriter() to respond to data, out.print(0) and out.print(1) are used to indicate success or failure, instead of out.write. For a reason, let’s first look at the similarities and differences between print and write.
The common point is: both do not refresh the page, but only write data on the original page. In the end, they both rewrite the write method in the abstract class Writer.
The difference is: the print method Various types of data can be converted into strings for output. The overloaded write method can only output characters, character arrays, strings and other character-related data.
So it is not difficult to find the difference between the two above. In the settings callback function in the js code of the page, what should be displayed is determined by the value returned from the server. If the last output in the server-side servlet is a number, and writ is used, the number will not be converted into a string and output, resulting in an incorrect judgment of the return value in the page.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Use ajax to verify whether the order number exists in the database
Ajax obtains the data and displays it on the front-end page
The above is the detailed content of How to use servlet output with Ajax technology. For more information, please follow other related articles on the PHP Chinese website!