What is the difference between Java Servlets and Java ServerPages (JSP)?

Alex Chaffee

Short answer: a JSP is a Servlet that thinks it's a Web page.

Medium answer: Both use server-side Java to dynamically generate web pages. The source code to a JSP looks like HTML, with Java embedded inside funny tags (*); the source code to a servlet looks like Java, with HTML embedded in out.print(...) statements. Both use the Servlet API to communicate with the web server and the client. In fact, a JSP gets compiled into a servlet, so they're almost identical in terms of expressive power. The choice is, whether you're more comfortable coding your pages in Java or in JSP-style HTML; and since you can call a JSP from a Servlet and vice versa, you don't have to make an either-or decision.

Long answer: See the Servlet FAQ and the JSP FAQ for all the information you need about both technologies.

(*) "Funny tags:" JSP can contain (a) normal HTML tags, (b) JSP tags like <jsp:include>, (c) custom tags, (d) scriptlets (Java code surrounded with <% and %>).