11 Answers
11

JSP is a Java view technology running on the server machine which allows you to write template text in (the client side languages like HTML, CSS, JavaScript and so on). JSP supports taglibs, which are backed by pieces of Java code that let you control the page flow or output dynamically. A well known taglib is JSTL. JSP also supports Expression Language, which can be used to access backend data (via attributes available in page, request, session and application scopes), mostly in combination with taglibs.

When a JSP is requested for the first time or when the webapp starts up, the servlet container will compile it into a class extending HttpServlet and use it during the webapp's lifetime. You can find the generated source code in the server's work directory. In for example Tomcat, it's the /work directory. On a JSP request, the servlet container will execute the compiled JSP class and send the generated output (usually just HTML/CSS/JS) through the webserver over network to the client side, which in turn displays it in the web browser.

Servlet is an Java application programming interface (API) running on the server machine, which intercepts requests made by the client and generates/sends a response. A well known example is the HttpServlet which provides methods to hook on HTTP requests using the popular HTTP methods such as GET and POST. You can configure HttpServlets to listen on a certain HTTP URL pattern, which is configurable in web.xml, or more recently with Java EE 6, with @WebServlet annotation.

When a Servlet is first requested or during webapp startup, the servlet container will create an instance of it and keep it in memory during the webapp's lifetime. The same instance will be reused for every incoming request whose URL matches the servlet's URL pattern. You can access the request data by HttpServletRequest and handle the response by HttpServletResponse. Both objects are available as method arguments inside any of the overridden methods of HttpServlet, such as doGet() and doPost().

JSF is a component based MVC framework which is built on top of the Servlet API, and provides components via taglibs which can be used in JSP or any other Java based view technology such as Facelets. Facelets is much more suited to JSF than JSP. It namely provides great templating capabilities such as composite components, while JSP basically only offers the <jsp:include> for templating, so that you're forced to create custom components with raw Java code (which is a bit opaque and a lot of tedious work in JSF) when you want to replace a repeated group of components with a single component. Since JSF 2.0, JSP has been deprecated as view technology in favor of Facelets.

As being a MVC (Model-View-Controller) framework, JSF provides the FacesServlet as the sole request-response Controller. It takes all the standard and tedious HTTP request/response work from your hands, such as gathering user input, validating/converting them, putting them in model objects, invoking actions and rendering the response. This way you end up with basically a JSP or Facelets (XHTML) page for View and a Javabean class as Model. The JSF components are been used to bind the view with the model (such as your ASP.NET web control does) and the FacesServlet uses the JSF component tree to do all the work.

@BalusC : I have seen this type of code used in jsp instead of java code - <c:forEach items="${items}"> <jsp:attribute name="var"> <mytag:doesSomething/> </jsp:attribute> What is this?
–
AshwinApr 23 '12 at 6:40

@BalusC I'm confused. What view technology are we supposed to be using? Java web apps seem to be all over the place, and it is the most confusing set of technologies to get start with I have ever seen.
–
johnnyJun 2 '14 at 17:15

JSP technology is part of the Java
technology family. JSP pages are
compiled into servlets and may call
JavaBeans components (beans) or
Enterprise JavaBeans components
(enterprise beans) to perform
processing on the server. As such, JSP
technology is a key component in a
highly scalable architecture for
web-based applications.

The Java Servlet API enables Java developers to write server-side code
for delivering dynamic Web content. Like other proprietary Web server
APIs, the Java Servlet API offered improved performance over CGI;
however, it has some key additional advantages. Because servlets were
coded in Java, they provides an object-oriented (OO) design approach
and, more important, are able to run on any platform. Thus, the same
code was portable to any host that supported Java. Servlets greatly
contributed to the popularity of Java, as it became a widely used
technology for server-side Web application development.

JSP :

JSP is built on top of servlets and provides a simpler, page-based
solution to generating large amounts of dynamic HTML content for Web
user interfaces. JavaServer Pages enables Web developers and designers
to simply edit HTML pages with special tags for the dynamic, Java
portions. JavaServer Pages works by having a special servlet known as
a JSP container, which is installed on a Web server and handles all
JSP page view requests. The JSP container translates a requested
JSP into servlet code that is then compiled and immediately executed.
Subsequent requests to the same page simply invoke the runtime servlet
for the page. If a change is made to the JSP on the server, a request
to view it triggers another translation, compilation, and restart of
the runtime servlet.

JSF :

JavaServer Faces is a standard Java framework for building user
interfaces for Web applications. Most important, it simplifies the
development of the user interface, which is often one of the more
difficult and tedious parts of Web application development.
Although it is possible to build user interfaces by using foundational
Java Web technologies(such as Java servlets and JavaServer Pages)
without a comprehensive framework designedfor enterprise Web
application development, these core technologies can often lead to
avariety of development and maintenance problems. More important, by
the time the developers achieve a production-quality solution, the
same set of problems solved by JSF will have been solved in a
nonstandard manner. JavaServer Faces is designed to simplify the
development of user interfaces for Java Web applications in the
following ways:
• It provides a component-centric,
client-independent development approach to building Web user
interfaces, thus improving developer productivity and ease of use.
• It simplifies the access and management of application data from the
Web user interface.
• It automatically manages the user interface
state between multiple requests and multiple clients in a simple and
unobtrusive manner.
• It supplies a development framework that is
friendly to a diverse developer audience with different skill sets.
• It describes a standard set of architectural patterns for a web
application.

It wasn't me, but I imagine it's because you just basically copy and pasted an answer from a book.
–
mawburnJul 31 '13 at 16:09

3

@Oberon: Thanks for the reply. It took a while for me to find the exact words so went for book. If its not appropriate, then you or any one can suggest me to take down the answer. I'll be glad to do it.
–
Kishor PAug 1 '13 at 4:21

that is true that JSP is converted into servlet at the time of execution, and JSF is totally new thing in order to make the webpage more readable as JSF allows to write all the programming structures in the form of tag.

The basic difference between Servlets and JSP is that in Servlets we write java code and in that we embed html code and there is just reverse case with jsp .
I JSP we write html code and in that we embed java code using tags provided by jsp.

JSP stands for JAVA SERVER PAGE........
jsp is not a servlet.
Jsp uses code and HTML tag both in itself you dont need to make a HTML and a servlet seprately.Jsp are playing magnificent role in web application.
Servlet is a java class plays an role to make your HTML page from static to dynamic .

JSF is a web application that is used to simplify development integration of web based user interfaces; JSP is a Java based technology used specifically in order to help software developers create dynamic web pages.

JSF contains multiple core features, including, but not limited to, Managed Beans, a template based component system, and two XML based tag libraries; JSP must be compiled in Java bytecode in order to function properly.