JSF、Servlet和JSP的区别是什么?

时间:2022-01-18 20:08:19

How are JSP and Servlet related to each other? Is JSP some kind of Servlet? How are JSP and JSF related to each other? Is JSF some kind of prebuild UI based JSP like ASP.NET-MVC?

JSP和Servlet是如何相互关联的?JSP是某种类型的Servlet吗?JSP和JSF是如何相互关联的?JSF是一种预先构建的基于UI的JSP,像ASP.NET-MVC吗?

16 个解决方案

#1


1087  

JSP (JavaServer Pages)

JSP is a Java view technology running on the server machine which allows you to write template text in client side languages (like HTML, CSS, JavaScript, ect.). 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 the page, request, session and application scopes), mostly in combination with taglibs.

JSP是在服务器机器上运行的Java视图技术,它允许您以客户端语言(如HTML、CSS、JavaScript等)编写模板文本。JSP支持taglibs,它由一些Java代码支持,这些代码可以让您动态地控制页面流或输出。著名的taglib是JSTL。JSP还支持表达式语言,它可以用于访问后端数据(通过在页面、请求、会话和应用程序范围内可用的属性),主要是与taglibs结合。

When a JSP is requested for the first time or when the web app starts up, the servlet container will compile it into a class extending HttpServlet and use it during the web app'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 web server over a network to the client side, which in turn displays it in the web browser.

当第一次请求JSP或web应用程序启动时,servlet容器将把它编译成一个扩展HttpServlet的类,并在web应用程序的生命周期中使用它。您可以在服务器的工作目录中找到生成的源代码。例如Tomcat,它是/work目录。在JSP请求上,servlet容器将执行已编译的JSP类,并通过web服务器将生成的输出(通常只是HTML/CSS/JS)发送到客户端,然后将其显示在web浏览器中。

Servlets

Servlet is a 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 to a certain HTTP URL pattern, which is configurable in web.xml, or more recently with Java EE 6, with @WebServlet annotation.

Servlet是在服务器机器上运行的Java应用程序编程接口(API),它拦截客户机发出的请求,并生成/发送响应。一个众所周知的示例是HttpServlet,它提供使用流行的HTTP方法(如GET和POST)对HTTP请求进行hook的方法。您可以配置HttpServlets来侦听特定的HTTP URL模式,该模式在web中是可配置的。xml,或者最近的Java EE 6,带有@WebServlet注释。

When a Servlet is first requested or during web app startup, the servlet container will create an instance of it and keep it in memory during the web app'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().

当一个Servlet被首次请求或在web应用程序启动时,Servlet容器将创建它的一个实例并在web应用程序的生命周期内将其保存在内存中。相同的实例将会被重复使用,每个请求的URL与servlet的URL模式匹配。您可以通过HttpServletRequest访问请求数据,并通过HttpServletResponse来处理响应。这两个对象都可以作为方法参数使用,如doGet()和doPost()。

JSF (JavaServer Faces)

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.

JSF是一个基于组件的MVC框架,它构建在Servlet API之上,并通过taglibs提供组件,可以在JSP或其他基于Java的视图技术(如Facelets)中使用。Facelets比JSP更适合JSF。它即提供伟大的模板功能,如复合组件,而JSP基本上只提供模板的< JSP:include >,所以你不得不创建自定义组件与原始的Java代码(这是不透明和乏味的工作在JSF)当你想重复组的组件替换为单个组件。自从JSF 2.0以来,JSP已经被弃用为支持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 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.

作为一个MVC(模型-视图-控制器)框架,JSF提供了FacesServlet作为唯一的请求-响应控制器。它从您的手中获取所有标准和冗长的HTTP请求/响应工作,例如收集用户输入、验证/转换它们、将它们放入模型对象、调用操作并呈现响应。这样,您就可以以基本的JSP或Facelets (XHTML)页面为视图,以JavaBean类作为模型。JSF组件用于将视图与模型绑定(比如您的ASP)。NET web控件是这样做的,FacesServlet使用JSF组件树来完成所有工作。

Related questions

#2


65  

See http://www.oracle.com/technetwork/java/faq-137059.html

见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.

JSP技术是Java技术家族的一部分。JSP页面被编译成servlet,可以调用JavaBeans组件(bean)或Enterprise JavaBeans组件(企业bean)来在服务器上执行处理。因此,JSP技术对于基于web的应用程序来说是高度可伸缩的体系结构中的关键组件。

See https://jcp.org/en/introduction/faq

参见https://jcp.org/en/introduction/faq

A: JavaServer Faces technology is a framework for building user interfaces for web applications. JavaServer Faces technology includes:

答:JavaServer Faces technology是一个为web应用程序构建用户界面的框架。JavaServer Faces技术包括:

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.

一组api:表示UI组件和管理它们的状态、处理事件和输入验证、定义页面导航、支持国际化和可访问性。

A JavaServer Pages (JSP) custom tag library for expressing a JavaServer Faces interface within a JSP page.

用于在JSP页面中表示JavaServer Faces接口的JavaServer Pages (JSP)自定义标记库。

JSP is a specialized kind of servlet.

JSP是一种特殊的servlet。

JSF is a set of tags you can use with JSP.

JSF是一组可以与JSP一起使用的标记。

#3


26  

From Browser/Client perspective

从浏览器/客户视角

JSP and JSF both looks same, As Per Application Requirements goes, JSP is more suited for request - response based applications.

JSP和JSF看起来都一样,根据应用程序的需求,JSP更适合于基于请求的应用程序。

JSF is targetted for richer event based Web applications. I see event as much more granular than request/response.

JSF的目标是更丰富的基于事件的Web应用程序。我认为事件比请求/响应更细粒度。

From Server Perspective

从服务器的角度来看

JSP page is converted to servlet, and it has only minimal behaviour.

JSP页面被转换为servlet,它的行为很少。

JSF page is converted to components tree(by specialized FacesServlet) and it follows component lifecycle defined by spec.

JSF页面被转换为组件树(由专门的FacesServlet),它遵循规范定义的组件生命周期。

#4


17  

Servlets :

servlet:

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.

Java Servlet API允许Java开发人员编写用于交付动态Web内容的服务器端代码。与其他专有Web服务器API一样,Java Servlet API提供了改进的CGI性能;然而,它还有一些关键的额外优势。因为servlet是用Java编写的,所以它们提供了面向对象(OO)的设计方法,更重要的是,它们能够在任何平台上运行。因此,相同的代码可以移植到任何支持Java的主机上。servlet极大地促进了Java的流行,因为它成为服务器端Web应用程序开发的广泛使用的技术。

JSP :

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.

JSP构建于servlet之上,并提供了一种更简单、基于页面的解决方案,可以为Web用户界面生成大量动态HTML内容。JavaServer Pages使Web开发人员和设计人员能够简单地编辑HTML页面,并为动态的Java部分添加特殊的标记。JavaServer页面的工作方式是拥有一个名为JSP容器的特殊servlet,它安装在Web服务器上,并处理所有JSP页面视图请求。JSP容器将请求的JSP转换为servlet代码,然后编译并立即执行。对同一页面的后续请求只是调用该页面的运行时servlet。如果对服务器上的JSP进行了更改,则需要查看它触发另一个翻译、编译和重新启动运行时servlet。

JSF :

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.

JavaServer Faces是一个用于为Web应用程序构建用户界面的标准Java框架。最重要的是,它简化了用户界面的开发,这通常是Web应用程序开发中比较困难和乏味的部分之一。尽管通过使用基础Java Web技术(如Java servlet和JavaServer页面)构建用户界面是可能的,但是如果没有针对企业Web应用程序开发的全面框架,这些核心技术通常会导致开发和维护问题的出现。更重要的是,当开发人员实现产品质量解决方案时,JSF解决的相同问题将以非标准的方式解决。JavaServer Faces的设计目的是简化Java Web应用程序的用户界面的开发:•它提供了一种以组件为中心的、以客户为中心的开发方法来构建Web用户界面,从而提高了开发人员的生产力和易用性。•简化了Web用户界面中应用程序数据的访问和管理。•它以一种简单而不唐突的方式自动管理多个请求和多个客户机之间的用户界面状态。•它提供了一个开发框架,对不同的开发人员有不同的技能。•它描述了web应用程序的一组标准的体系结构模式。

[ Source : Complete reference:JSF ]

[来源:完整参考:JSF]

#5


13  

There are also situations where you can favor JSP over JSF. The application nature should be the deciding factor to choose the technology.

在某些情况下,您还可以在JSF上支持JSP。应用的性质应该是选择技术的决定性因素。

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.

如果您有丰富的GUI交互,并且需要大量的Java脚本,那么就支持JSF。基本上,如果你的GUI应用程序架构像面向组件的,甚至是驱动的,那么JSF是最好的。

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.

如果应用程序只是一个简单的表单提交,不需要太多的GUI交互,那么JSP可以很好地完成,如果学习一种新技术是一种开销,而且复杂的框架是不必要的。

#6


10  

Servlet - it's java server side layer.

Servlet——它是java服务器端层。

  • JSP - it's Servlet with html
  • JSP—它是html的Servlet。
  • JSF - it's components base on tag libs
  • JSF -它的组件基于标签libs。
  • JSP - it's converted into servlet once when server got request.
  • JSP—当服务器收到请求时,它被转换为servlet。

#7


8  

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会被转换为servlet,而JSF则是全新的东西,以便使页面更容易阅读,因为JSF允许以标记的形式编写所有的编程结构。

#8


2  

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.

Java Server Pages (JSP)是一种Java技术,它使Web开发人员和设计人员能够快速开发和轻松维护那些利用现有业务系统的信息丰富的动态Web页面。JSP技术将用户界面与内容生成分离开来,使设计人员能够在不改变底层动态内容的情况下改变整个页面布局。

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.

Facelets是为JSF (Java Server Faces)设计的第一个非JSP页面声明语言,它为JSF开发人员提供了一个比JSP更简单、更强大的编程模型。它解决了web应用程序开发JSP中出现的不同问题。

Here is a table that compares the features of scriplets and facelets:

这里有一张表,比较了对联和facelets的特点:

JSF、Servlet和JSP的区别是什么? Source

#9


2  

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.

servlet和JSP的基本区别在于,在servlet中,我们编写java代码,并在其中嵌入HTML代码,而JSP则刚好相反。在JSP中,我们编写HTML代码,并使用JSP提供的标记嵌入java代码。

#10


0  

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.

JSF是一个高级框架,它很容易实现基于模型-视图-控制器(MVC)的项目架构。JSF在JSP上的主要优势是基于条件的简单动态呈现,以及ajax事件的简单集成。

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.

JSF应用程序的前端,即xhtml文件,是通过浏览器向用户显示的。这些xhtml文件在内部调用托管bean,例如编写实际应用程序逻辑的控制器。

The controllers internally invoke various services which communicate with database (using Hibernate or JPA API). This is how the flow happens in short.

控制器内部调用与数据库通信的各种服务(使用Hibernate或JPA API)。这就是流如何在短时间内发生的。

JSF is also used in combination with RichFaces which is a framework for giving rich look and feel to your web application.

JSF还与RichFaces结合使用,RichFaces是为您的web应用程序提供丰富的外观和感觉的框架。

JSF + RichFaces + Hibernate/JPA is a good technology to learn for sure !

JSF + RichFaces + Hibernate/JPA是一个很好的学习技术!

#11


-1  

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.

Jsp也有构建的servlet代码,它不需要任何外部编译,它可以直接运行。更改将在浏览器中直接生效。

Servlet need to be compiled (i.e it will have specific class creation)

Servlet需要编译(我。它将具有特定的类创建)

Jsf is a view component of MVC Framework

Jsf是MVC框架的视图组件。

#12


-1  

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 .

JSP代表JAVA服务器页面……。jsp不是一个servlet。Jsp使用代码和HTML标签本身,您不需要做一个HTML和一个servlet。Jsp在web应用程序中扮演着非常重要的角色。Servlet是一个java类,它可以使您的HTML页面从静态变为动态。

#13


-1  

  1. 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是一个web应用程序,用于简化基于web的用户界面的开发集成;JSP是一种专门用于帮助软件开发人员创建动态web页面的基于Java的技术。

  2. 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.

    JSF包含多个核心特性,包括但不限于托管bean、基于模板的组件系统和两个基于XML的标记库;为了正常工作,JSP必须在Java字节码中编译。

#14


-1  

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.

jsp是MVC(模型视图控制器)的视图组件。控制器接收传入的请求并将其传递给模型,该模型可能是执行某些数据库访问的bean。然后,JSP使用HTML、CSS和JavaScript格式化输出,然后输出返回给请求者。

#15


-1  

JSP:means HTML+Java Code:

JSP have it's own life cycle jsp_init() jsp_service() jsp_destroy

JSP拥有自己的生命周期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

首先请求JSP转换为.java文件。有三种类型的标签我们使用1.)Scriptless。

<%  %>

Here developer can declare all those things which developer want to take the data

在这里,开发人员可以声明所有那些开发人员想要获取数据的东西。

2.)Expression tag

2)。表达标记

<%=  %>

Here developer can use some print related data

这里开发人员可以使用一些打印相关的数据。

3.)Declaration

3)声明

<!% %>

Here developer can declare some method related data.

这里开发人员可以声明一些方法相关的数据。

Servlet:

Servlet have it's own life cycle.

Servlet拥有自己的生命周期。

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.

第一个请求容器将从web读取数据。xml文件之后,欢迎填充将显示。在执行操作之后,它会搜索url然后在这个过程之后它会搜索这个特定的servlet。服务操作执行。

JSF:

JSF have it's own ui and it's life cycle can perform in six way,

JSF有自己的ui,它的生命周期可以用六种方式进行,

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.

#16


-1  

There are a few differences between JSP and Servlet:

JSP和Servlet之间有一些区别:

  • As mentioned above in JSP, Java code is embedded in HTML code where as in Servlets, HTML code is embedded in Java code.

    正如在JSP中所提到的,Java代码嵌入在HTML代码中,就像在servlet中一样,HTML代码嵌入在Java代码中。

  • JSPs are the extensions of servlets.

    jsp是servlet的扩展。

  • One more advantage of Jsps are the implicit objects. Refer javatpoint implicit objects in JSP

    jsp的另一个优点是隐式对象。在JSP中引用javatpoint隐式对象。

#1


1087  

JSP (JavaServer Pages)

JSP is a Java view technology running on the server machine which allows you to write template text in client side languages (like HTML, CSS, JavaScript, ect.). 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 the page, request, session and application scopes), mostly in combination with taglibs.

JSP是在服务器机器上运行的Java视图技术,它允许您以客户端语言(如HTML、CSS、JavaScript等)编写模板文本。JSP支持taglibs,它由一些Java代码支持,这些代码可以让您动态地控制页面流或输出。著名的taglib是JSTL。JSP还支持表达式语言,它可以用于访问后端数据(通过在页面、请求、会话和应用程序范围内可用的属性),主要是与taglibs结合。

When a JSP is requested for the first time or when the web app starts up, the servlet container will compile it into a class extending HttpServlet and use it during the web app'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 web server over a network to the client side, which in turn displays it in the web browser.

当第一次请求JSP或web应用程序启动时,servlet容器将把它编译成一个扩展HttpServlet的类,并在web应用程序的生命周期中使用它。您可以在服务器的工作目录中找到生成的源代码。例如Tomcat,它是/work目录。在JSP请求上,servlet容器将执行已编译的JSP类,并通过web服务器将生成的输出(通常只是HTML/CSS/JS)发送到客户端,然后将其显示在web浏览器中。

Servlets

Servlet is a 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 to a certain HTTP URL pattern, which is configurable in web.xml, or more recently with Java EE 6, with @WebServlet annotation.

Servlet是在服务器机器上运行的Java应用程序编程接口(API),它拦截客户机发出的请求,并生成/发送响应。一个众所周知的示例是HttpServlet,它提供使用流行的HTTP方法(如GET和POST)对HTTP请求进行hook的方法。您可以配置HttpServlets来侦听特定的HTTP URL模式,该模式在web中是可配置的。xml,或者最近的Java EE 6,带有@WebServlet注释。

When a Servlet is first requested or during web app startup, the servlet container will create an instance of it and keep it in memory during the web app'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().

当一个Servlet被首次请求或在web应用程序启动时,Servlet容器将创建它的一个实例并在web应用程序的生命周期内将其保存在内存中。相同的实例将会被重复使用,每个请求的URL与servlet的URL模式匹配。您可以通过HttpServletRequest访问请求数据,并通过HttpServletResponse来处理响应。这两个对象都可以作为方法参数使用,如doGet()和doPost()。

JSF (JavaServer Faces)

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.

JSF是一个基于组件的MVC框架,它构建在Servlet API之上,并通过taglibs提供组件,可以在JSP或其他基于Java的视图技术(如Facelets)中使用。Facelets比JSP更适合JSF。它即提供伟大的模板功能,如复合组件,而JSP基本上只提供模板的< JSP:include >,所以你不得不创建自定义组件与原始的Java代码(这是不透明和乏味的工作在JSF)当你想重复组的组件替换为单个组件。自从JSF 2.0以来,JSP已经被弃用为支持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 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.

作为一个MVC(模型-视图-控制器)框架,JSF提供了FacesServlet作为唯一的请求-响应控制器。它从您的手中获取所有标准和冗长的HTTP请求/响应工作,例如收集用户输入、验证/转换它们、将它们放入模型对象、调用操作并呈现响应。这样,您就可以以基本的JSP或Facelets (XHTML)页面为视图,以JavaBean类作为模型。JSF组件用于将视图与模型绑定(比如您的ASP)。NET web控件是这样做的,FacesServlet使用JSF组件树来完成所有工作。

Related questions

#2


65  

See http://www.oracle.com/technetwork/java/faq-137059.html

见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.

JSP技术是Java技术家族的一部分。JSP页面被编译成servlet,可以调用JavaBeans组件(bean)或Enterprise JavaBeans组件(企业bean)来在服务器上执行处理。因此,JSP技术对于基于web的应用程序来说是高度可伸缩的体系结构中的关键组件。

See https://jcp.org/en/introduction/faq

参见https://jcp.org/en/introduction/faq

A: JavaServer Faces technology is a framework for building user interfaces for web applications. JavaServer Faces technology includes:

答:JavaServer Faces technology是一个为web应用程序构建用户界面的框架。JavaServer Faces技术包括:

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.

一组api:表示UI组件和管理它们的状态、处理事件和输入验证、定义页面导航、支持国际化和可访问性。

A JavaServer Pages (JSP) custom tag library for expressing a JavaServer Faces interface within a JSP page.

用于在JSP页面中表示JavaServer Faces接口的JavaServer Pages (JSP)自定义标记库。

JSP is a specialized kind of servlet.

JSP是一种特殊的servlet。

JSF is a set of tags you can use with JSP.

JSF是一组可以与JSP一起使用的标记。

#3


26  

From Browser/Client perspective

从浏览器/客户视角

JSP and JSF both looks same, As Per Application Requirements goes, JSP is more suited for request - response based applications.

JSP和JSF看起来都一样,根据应用程序的需求,JSP更适合于基于请求的应用程序。

JSF is targetted for richer event based Web applications. I see event as much more granular than request/response.

JSF的目标是更丰富的基于事件的Web应用程序。我认为事件比请求/响应更细粒度。

From Server Perspective

从服务器的角度来看

JSP page is converted to servlet, and it has only minimal behaviour.

JSP页面被转换为servlet,它的行为很少。

JSF page is converted to components tree(by specialized FacesServlet) and it follows component lifecycle defined by spec.

JSF页面被转换为组件树(由专门的FacesServlet),它遵循规范定义的组件生命周期。

#4


17  

Servlets :

servlet:

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.

Java Servlet API允许Java开发人员编写用于交付动态Web内容的服务器端代码。与其他专有Web服务器API一样,Java Servlet API提供了改进的CGI性能;然而,它还有一些关键的额外优势。因为servlet是用Java编写的,所以它们提供了面向对象(OO)的设计方法,更重要的是,它们能够在任何平台上运行。因此,相同的代码可以移植到任何支持Java的主机上。servlet极大地促进了Java的流行,因为它成为服务器端Web应用程序开发的广泛使用的技术。

JSP :

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.

JSP构建于servlet之上,并提供了一种更简单、基于页面的解决方案,可以为Web用户界面生成大量动态HTML内容。JavaServer Pages使Web开发人员和设计人员能够简单地编辑HTML页面,并为动态的Java部分添加特殊的标记。JavaServer页面的工作方式是拥有一个名为JSP容器的特殊servlet,它安装在Web服务器上,并处理所有JSP页面视图请求。JSP容器将请求的JSP转换为servlet代码,然后编译并立即执行。对同一页面的后续请求只是调用该页面的运行时servlet。如果对服务器上的JSP进行了更改,则需要查看它触发另一个翻译、编译和重新启动运行时servlet。

JSF :

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.

JavaServer Faces是一个用于为Web应用程序构建用户界面的标准Java框架。最重要的是,它简化了用户界面的开发,这通常是Web应用程序开发中比较困难和乏味的部分之一。尽管通过使用基础Java Web技术(如Java servlet和JavaServer页面)构建用户界面是可能的,但是如果没有针对企业Web应用程序开发的全面框架,这些核心技术通常会导致开发和维护问题的出现。更重要的是,当开发人员实现产品质量解决方案时,JSF解决的相同问题将以非标准的方式解决。JavaServer Faces的设计目的是简化Java Web应用程序的用户界面的开发:•它提供了一种以组件为中心的、以客户为中心的开发方法来构建Web用户界面,从而提高了开发人员的生产力和易用性。•简化了Web用户界面中应用程序数据的访问和管理。•它以一种简单而不唐突的方式自动管理多个请求和多个客户机之间的用户界面状态。•它提供了一个开发框架,对不同的开发人员有不同的技能。•它描述了web应用程序的一组标准的体系结构模式。

[ Source : Complete reference:JSF ]

[来源:完整参考:JSF]

#5


13  

There are also situations where you can favor JSP over JSF. The application nature should be the deciding factor to choose the technology.

在某些情况下,您还可以在JSF上支持JSP。应用的性质应该是选择技术的决定性因素。

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.

如果您有丰富的GUI交互,并且需要大量的Java脚本,那么就支持JSF。基本上,如果你的GUI应用程序架构像面向组件的,甚至是驱动的,那么JSF是最好的。

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.

如果应用程序只是一个简单的表单提交,不需要太多的GUI交互,那么JSP可以很好地完成,如果学习一种新技术是一种开销,而且复杂的框架是不必要的。

#6


10  

Servlet - it's java server side layer.

Servlet——它是java服务器端层。

  • JSP - it's Servlet with html
  • JSP—它是html的Servlet。
  • JSF - it's components base on tag libs
  • JSF -它的组件基于标签libs。
  • JSP - it's converted into servlet once when server got request.
  • JSP—当服务器收到请求时,它被转换为servlet。

#7


8  

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会被转换为servlet,而JSF则是全新的东西,以便使页面更容易阅读,因为JSF允许以标记的形式编写所有的编程结构。

#8


2  

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.

Java Server Pages (JSP)是一种Java技术,它使Web开发人员和设计人员能够快速开发和轻松维护那些利用现有业务系统的信息丰富的动态Web页面。JSP技术将用户界面与内容生成分离开来,使设计人员能够在不改变底层动态内容的情况下改变整个页面布局。

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.

Facelets是为JSF (Java Server Faces)设计的第一个非JSP页面声明语言,它为JSF开发人员提供了一个比JSP更简单、更强大的编程模型。它解决了web应用程序开发JSP中出现的不同问题。

Here is a table that compares the features of scriplets and facelets:

这里有一张表,比较了对联和facelets的特点:

JSF、Servlet和JSP的区别是什么? Source

#9


2  

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.

servlet和JSP的基本区别在于,在servlet中,我们编写java代码,并在其中嵌入HTML代码,而JSP则刚好相反。在JSP中,我们编写HTML代码,并使用JSP提供的标记嵌入java代码。

#10


0  

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.

JSF是一个高级框架,它很容易实现基于模型-视图-控制器(MVC)的项目架构。JSF在JSP上的主要优势是基于条件的简单动态呈现,以及ajax事件的简单集成。

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.

JSF应用程序的前端,即xhtml文件,是通过浏览器向用户显示的。这些xhtml文件在内部调用托管bean,例如编写实际应用程序逻辑的控制器。

The controllers internally invoke various services which communicate with database (using Hibernate or JPA API). This is how the flow happens in short.

控制器内部调用与数据库通信的各种服务(使用Hibernate或JPA API)。这就是流如何在短时间内发生的。

JSF is also used in combination with RichFaces which is a framework for giving rich look and feel to your web application.

JSF还与RichFaces结合使用,RichFaces是为您的web应用程序提供丰富的外观和感觉的框架。

JSF + RichFaces + Hibernate/JPA is a good technology to learn for sure !

JSF + RichFaces + Hibernate/JPA是一个很好的学习技术!

#11


-1  

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.

Jsp也有构建的servlet代码,它不需要任何外部编译,它可以直接运行。更改将在浏览器中直接生效。

Servlet need to be compiled (i.e it will have specific class creation)

Servlet需要编译(我。它将具有特定的类创建)

Jsf is a view component of MVC Framework

Jsf是MVC框架的视图组件。

#12


-1  

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 .

JSP代表JAVA服务器页面……。jsp不是一个servlet。Jsp使用代码和HTML标签本身,您不需要做一个HTML和一个servlet。Jsp在web应用程序中扮演着非常重要的角色。Servlet是一个java类,它可以使您的HTML页面从静态变为动态。

#13


-1  

  1. 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是一个web应用程序,用于简化基于web的用户界面的开发集成;JSP是一种专门用于帮助软件开发人员创建动态web页面的基于Java的技术。

  2. 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.

    JSF包含多个核心特性,包括但不限于托管bean、基于模板的组件系统和两个基于XML的标记库;为了正常工作,JSP必须在Java字节码中编译。

#14


-1  

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.

jsp是MVC(模型视图控制器)的视图组件。控制器接收传入的请求并将其传递给模型,该模型可能是执行某些数据库访问的bean。然后,JSP使用HTML、CSS和JavaScript格式化输出,然后输出返回给请求者。

#15


-1  

JSP:means HTML+Java Code:

JSP have it's own life cycle jsp_init() jsp_service() jsp_destroy

JSP拥有自己的生命周期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

首先请求JSP转换为.java文件。有三种类型的标签我们使用1.)Scriptless。

<%  %>

Here developer can declare all those things which developer want to take the data

在这里,开发人员可以声明所有那些开发人员想要获取数据的东西。

2.)Expression tag

2)。表达标记

<%=  %>

Here developer can use some print related data

这里开发人员可以使用一些打印相关的数据。

3.)Declaration

3)声明

<!% %>

Here developer can declare some method related data.

这里开发人员可以声明一些方法相关的数据。

Servlet:

Servlet have it's own life cycle.

Servlet拥有自己的生命周期。

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.

第一个请求容器将从web读取数据。xml文件之后,欢迎填充将显示。在执行操作之后,它会搜索url然后在这个过程之后它会搜索这个特定的servlet。服务操作执行。

JSF:

JSF have it's own ui and it's life cycle can perform in six way,

JSF有自己的ui,它的生命周期可以用六种方式进行,

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.

#16


-1  

There are a few differences between JSP and Servlet:

JSP和Servlet之间有一些区别:

  • As mentioned above in JSP, Java code is embedded in HTML code where as in Servlets, HTML code is embedded in Java code.

    正如在JSP中所提到的,Java代码嵌入在HTML代码中,就像在servlet中一样,HTML代码嵌入在Java代码中。

  • JSPs are the extensions of servlets.

    jsp是servlet的扩展。

  • One more advantage of Jsps are the implicit objects. Refer javatpoint implicit objects in JSP

    jsp的另一个优点是隐式对象。在JSP中引用javatpoint隐式对象。