Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Doubt  RSS feed

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP expressions become out.print() in the _jspService() method and plain old template text becomes out.write() in the _jspService() method.

I am sure the first one is correct but am not sure with the second one. Is is the second one correct.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is perfectly legitimate.
It just saves an interim method call

JspWriter extends java.io.Writer.
java.io.Writer provides the method "write(String s)"
Most of the print* methods will just indirectly call the writer.
The print method has to be used for expressions, because you don't know the type of the argument. With template text, you know the type is String, so can use the method write.
Also the print(String s) method is tasked with printing out "null" if the argument is null. As you know the argument being passed is not null, you can just call write directly.

So they save an entire method call, and an if statement for every out.write() they use instead of an out.print(). Given the amount of times this happens in a JSP, it seems a worthwile optimization.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!