This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JSP and the fly likes Simple Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Simple Doubt" Watch "Simple Doubt" New topic
Author

Simple Doubt

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1008
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Simple Doubt
 
Similar Threads
Mock exam questions
Mock exam question doubt?
jspInit() method
Mock Questions
Please Check Two Statements