Servlet versus JSP
- Both a servlet and JSP are "called" with a reference to to them as a web page, but they are executed differently and used for different types of problems.
- A servlet is a complete Java program that generates browser-readable output (typically HTML). (So, HTML embedded as output in Java code.)
- JSP is snippets of java code embedded in an HTML page. (So, Java code embedded in HTML.)
- Servlets are compiled once, then the .class file is executed by the container (i.e. TomCat).
- JSP is compiled each time it is executed, so a syntax error results in a "run-time" error.
- Servlets are server processes, so once they start, they continue running.
- Servlets are multi-threaded - to handle each Client request, a new thread is executed on the Servlet object.
- JSP is re-executed each time it is "called".