Home > Backend Development > PHP Tutorial > Detailed explanation of the output stream example at the end of servlet in Ajax technology

Detailed explanation of the output stream example at the end of servlet in Ajax technology

小云云
Release: 2023-03-19 13:40:02
Original
1296 people have browsed it

This article mainly introduces the relevant information about the output stream at the end of the servlet in Ajax technology. It is very good and has reference value. Friends who need it can refer to it. I hope it can help everyone.

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 setting callback function in the js code of the page, the value returned from the server is used to determine what to display. If the last value in the server-side servlet If the output is a number, and using writ, the number will not be converted into a string and output, which will lead to an incorrect judgment of the return value on the page.

Related recommendations:

jquery request servlet to implement ajax asynchronous request example sharing

Servlet+Ajax to implement intelligent search box intelligence Prompt function

Steps to implement file upload using js and servlet in h5

The above is the detailed content of Detailed explanation of the output stream example at the end of servlet in Ajax technology. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template