Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE 6: JSF vs Servlet + JSP. Should I bother learning JSF?

I am trying to get familiar with Java EE 6 by reading http://java.sun.com/javaee/6/docs/tutorial/doc/gexaf.html. I am a bit confused about the use of JSF.
Usually, the way I develop my Web App would be, Servlet would act like a controller and JSP would act like a View in an MVC model. So Does JSF try to replace this structure? Below are the quote from the above tutorial:

Servlet are best suited for service-oriented App and control function of presentation-oriented App like dispatching request
JSF and Facelet are more appropriated for generating mark-up like XHTML, and generally used for presentation-oriented App

Not sure if I understand the above quote too well, they did not explain too well what is service-oriented vs presentation-oriented.

A JavaServer Faces application can map HTTP requests to component-specific event handling and manage components as stateful objects on the server.

Any knowledgeable Java developer out there can give me a quick overview about JSF, JSP and Servlet? Do I integrate them all, or do I use them separated base on the App? if so then what kind of app use JSF in contrast with Servlet and JSP

A JavaServer Faces application can map HTTP requests to component-specific event handling and manage components as stateful objects on the server.

Sound like what servlet can do, but not sure about manage components as stateful objects on the server. Not even sure what that mean? Thanks in advance.

like image 659
Thang Pham Avatar asked Apr 23 '10 18:04

Thang Pham


People also ask

Is JSF better than JSP?

JSF is a proper framework that connects a data source with a reuseable UI component, provides support for multiple libraries, and decreases the effort to build and manage applications. Being component-based, JSF always has a good security advantage over JSP.

Is JSP and JSF same?

JSF is a web-based application that is used to simplify the development integration of web-based user interfaces. While JSP is a Java-based technology used respectively in order to support software developers create dynamic web pages. JSP must be compiled in Java bytecode in order to work properly.

Is JSP better than servlet?

Servlets can accept and process all type of protocol requests. JSP on the other hand is compatible with HTTP request only. In Servlet by default session management is not enabled, the user has to enable it explicitly. On the other hand in JSP session management is automatically enabled.

Is JSF part of Java EE?

Jakarta Server Faces (JSF; formerly JavaServer Faces) is a Java specification for building component-based user interfaces for web applications and was formalized as a standard through the Java Community Process being part of the Java Platform, Enterprise Edition.


1 Answers

JSF basically enables you to develop a web application with only model objects (JavaBeans) and views (JSP/XHTML pages). With "plain vanilla" JSP/Servlet you'll have to bring in a lot of code to control, preprocess, postprocess, gather data, validate, convert, listen, etc the HTTP request and response. And then I'm not talking about refactoring it to a high (abstract) degree so that you can also end up the same way as JSF does (just a JavaBean class and a JSP/XHTML page per use case).

I've posted a more detailed answer on the subject before here: What is the difference between JSF, Servlet and JSP?

like image 159
BalusC Avatar answered Sep 30 '22 05:09

BalusC