Nearby lessons
4 of 30JSP - Template Text
- Understand what template text is
- Know how the container processes template text
- See how template text appears in the generated servlet
Template Text is any static content in a JSP page — HTML, XML, plain text — that is sent directly to the browser without processing. This lesson explains how template text works and how it relates to the generated servlet.
What is Template Text?
Template text is any content in a JSP page that is not a directive, action, or scripting element. It includes:
- Plain text
- HTML tags and attributes
- XML tags
For template text, no processing is required — it becomes an argument to the out.write() method inside the _jspService() method of the generated servlet.
Example JSP:
Generated Servlet
For the above JSP, the generated servlet contains:
Why write() vs print()?
Template text uses out.write() because:
write()can only take character data as an argumentprint()can take any type of data as an argument
Since template text is always character data, it becomes the argument of write().
Since an expression value can be any type (string, number, object), it must use print() which accepts any type.
- Template text is any static content in the JSP page
- It becomes an argument to out.write() in the generated servlet
- Expression values become arguments to print() instead