I have some questions. These are :
This question is related to
java
jsp
jsf
servlets
jakarta-ee
Servlets :
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.
[ Source : Complete reference:JSF ]
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 . In JSP we write HTML code and in that we embed java code using tags provided by JSP.
See http://www.oracle.com/technetwork/java/faq-137059.html
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.
See https://jcp.org/en/introduction/faq
A: JavaServer Faces technology is a framework for building user interfaces for web applications. JavaServer Faces technology includes:
A set of APIs for: representing UI components and managing their state, handling events and input validation, defining page navigation, and supporting internationalization and accessibility.
A JavaServer Pages (JSP) custom tag library for expressing a JavaServer Faces interface within a JSP page.
JSP is a specialized kind of servlet.
JSF is a set of tags you can use with JSP.
JSP:means HTML+Java Code:
JSP have it's own life cycle jsp_init() jsp_service() jsp_destroy
After first request JSP convert to .java file. There is three type of tag we are using
1.)Scriptless
<% %>
Here developer can declare all those things which developer want to take the data
2.)Expression tag
<%= %>
Here developer can use some print related data
3.)Declaration
<!% %>
Here developer can declare some method related data.
Servlet:
Servlet have it's own life cycle.
init()
service()
destroy()
After first request container will read the data from web.xml file
then after out welcome fill will be display.
Now onward after performing action it will search the url and after this process it will search the particular servlet there it self. service operation will perform.
JSF:
JSF have it's own ui and it's life cycle can perform in six way,
A)Restore view phase
B)Apply request values phase
C)Process validations phase
D)Update model values phase
E)Invoke application phase
F)Render response phase
For ui here for table here we are using panel grid and there is different faces for this that is.
Rich Faces
Prime Faces.
Servlets are the server side java programs which execute inside the web container. The main goal of the servlet is to process the requests received from the client.
Java Server Pages is used to create dynamic web pages. Jsp's were introduced to write java plus html code in a single file which was not easy to do in servlets program. And a jsp file is converted to a java servlet when it is translated.
Java Server Faces is a MVC web framework which simplifies the development of UI.
JSF is an advanced framework wherein its very easy to implement Model-View-Controller (MVC) based architecture for projects. Main advantage of JSF over JSP is the easy dynamic rendering of the components on the browser based upon conditions and easy integration of ajax events.
The front end of the JSF application i.e. xhtml files are the ones which are shown to the user via browser. These xhtml files internally invoke managed beans e.g. controllers wherein actual application logic is written.
The controllers internally invoke various services which communicate with database (using Hibernate or JPA API). This is how the flow happens in short.
JSF is also used in combination with RichFaces which is a framework for giving rich look and feel to your web application.
JSF + RichFaces + Hibernate/JPA is a good technology to learn for sure !
From Browser/Client perspective
JSP and JSF both looks same, As Per Application Requirements goes, JSP is more suited for request - response based applications.
JSF is targetted for richer event based Web applications. I see event as much more granular than request/response.
From Server Perspective
JSP page is converted to servlet, and it has only minimal behaviour.
JSF page is converted to components tree(by specialized FacesServlet) and it follows component lifecycle defined by spec.
Jsp is also having in built servlet code which don't need any external compilation it can be run directly run. Changes will take effect in jsp directly in a browser.
Servlet need to be compiled (i.e it will have specific class creation)
Jsf is a view component of MVC Framework
JSPs are the View component of MVC (Model View Controller). The Controller takes the incoming request and passes it to the Model, which might be a bean that does some database access. The JSP then formats the output using HTML, CSS and JavaScript, and the output then gets sent back to the requester.
There are also situations where you can favor JSP over JSF. The application nature should be the deciding factor to choose the technology.
If you have a rich GUI interaction and lot of Java scripting needed then favor JSF. Basically if your GUI app architecture is like Component oriented & even driven like Swing then JSF is the best.
If the application is just a plain form submitting, not much of GUI interaction needed, then JSP could do well if learning a new tech is an overhead and also complex framework is unnecessary.
Servlet - it's java server side layer.
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.
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 .
Java Server Pages (JSP) is java technology which enables Web developers and designers to rapidly develop and easily maintain, information-rich, dynamic Web pages that leverage existing business systems. JSP technology separates the user interface from content generation, enabling designers to change the overall page layout without altering the underlying dynamic content.
Facelets is the first non JSP page declaration language designed for JSF (Java Server Faces) which provided a simpler and more powerful programming model to JSF developers as compare to JSP. It resolves different issues occurs in JSP for web applications development.
Here is a table that compares the features of scriplets and facelets:
Source: Stackoverflow.com