An in depth analysis of the differences between out. print and out. write in Jsp

  • 2021-12-12 09:23:55
  • OfStack

The out object in jsp is of type JspWriter.

And JspWriter inherits java. io. Writer.

The write method is defined in the parent class Writer,

The print method is defined in the subclass JspWriter.

Overloaded print methods can convert various types of data into strings for output.

Overloaded write methods can only output character-related data such as characters/character arrays/strings, and if you use both methods to output a string object with the value null, the print method outputs "null" and the write method throws an NullPoiterException exception.

out. write () is a byte output stream method

out. print () is the method of character output stream

In jsp, out is HttpServletResponse.getWriter(), Is a character output stream

So most of them use print

The above is the site to introduce you out. print and out. write difference, I hope to help you, if you have any questions welcome to give me a message, this site will reply to you in time!


Related articles: