What are the differences between JSP and Facelets?

Alex Ntousias picture Alex Ntousias · Feb 4, 2010 · Viewed 11.7k times · Source

I just started reading the Java EE 6 Tutorial, and I'm a little confused! I knew about JavaServer Pages (JSP), and even did some coding during my undergraduate studies. But now, in this tutorial, I don't see anything about JSP.

Instead I read about Facelets, a new View Definition Framework (as it is described in this tutorial). I searched a little bit over the Internet to clarify the distinction between JSP and Facelets, and I came across with this post that helped me a lot (especially BalusC's answer). But these terms are still a little unclear to me.

What is the difference between JSP and Facelets? Are Facelets going to replace JSP, or is it just a technology that works better with JSF (and if it's the latter, why)? If they are different, when should I use each one of them?

Answer

Adeel Ansari picture Adeel Ansari · Feb 4, 2010

As you can read from the tutorial,

The term Facelets is used to refer to the JavaServerTM Faces View Definition Framework, which is a page declaration language that was developed for use with JavaServer Faces technology. As of JavaServer Faces 2.0, Facelets is a part of JavaServer Faces specification and also the preferred presentation technology for building JavaServer Faces based applications.

Now, JSP is the standard view technology for the web. But when it comes to adopt JSF as a web framework, JSP doesn't support all the features provided in JSF 2.0. Therefore, there was a need of some standard view technology to work with JSF 2.0. So, Facelets is just that.

If you are not working with JSF at all, you don't need to employ Facelets. You can go with JSP in that case. Or there are few other template frameworks, like FreeMarker, and Velocity. Moreover, some web frameworks, defines there own mark-up, like Struts2. So if you decided to go with Struts, using Struts mark-up is the way to go.