JSF,Servlet和JSP有什么区别?

本文翻译自:What is the difference between JSF, Servlet and JSP?

How are JSP and Servlet related to each other? JSP和Servlet如何相互关联? Is JSP some kind of Servlet? JSP是某种Servlet吗? How are JSP and JSF related to each other? JSP和JSF如何相互关联? Is JSF some kind of prebuild UI based JSP like ASP.NET-MVC? JSF是一种基于预构建UI的JSP,如ASP.NET-MVC吗?


#1楼

参考:https://stackoom.com/question/8n6j/JSF-Servlet和JSP有什么区别


#2楼

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. JSF针对更丰富的基于事件的Web应用程序。 I see event as much more granular than request/response. 我认为事件比请求/响应更精细。

From Server Perspective 从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),它遵循spec定义的组件生命周期。


#3楼

There are also situations where you can favor JSP over JSF. 在某些情况下,您可以支持JSP而不是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. 如果你有丰富的GUI交互和大量的Java脚本需要,那么赞成JSF。 Basically if your GUI app architecture is like Component oriented & even driven like Swing then JSF is the best. 基本上,如果您的GUI应用程序架构像面向组件甚至像Swing一样驱动,那么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可以做得很好。


#4楼

Servlets : Servlets:

The Java Servlet API enables Java developers to write server-side code for delivering dynamic Web content. Java Servlet API使Java开发人员能够编写用于提供动态Web内容的服务器端代码。 Like other proprietary Web server APIs, the Java Servlet API offered improved performance over CGI; 与其他专有Web服务器API一样,Java Servlet API提供了比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. 因为servlet是用Java编写的,所以它们提供面向对象(OO)设计方法,更重要的是,它们能够在任何平台上运行。 Thus, the same code was portable to any host that supported Java. 因此,相同的代码可以移植到任何支持Java的主机。 Servlets greatly contributed to the popularity of Java, as it became a widely used technology for server-side Web application development. 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. JSP构建于servlet之上,提供了一种更简单的基于页面的解决方案,可为Web用户界面生成大量动态HTML内容。 JavaServer Pages enables Web developers and designers to simply edit HTML pages with special tags for the dynamic, Java portions. JavaServer Pages使Web开发人员和设计人员能够简单地编辑带有动态Java部分特殊标记的HTML页面。 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. JavaServer Pages通过一个称为JSP容器的特殊servlet来工作,该容器安装在Web服务器上并处理所有JSP页面查看请求。 The JSP container translates a requested JSP into servlet code that is then compiled and immediately executed. JSP容器将请求的JSP转换为servlet代码,然后编译并立即执行。 Subsequent requests to the same page simply invoke the runtime servlet for the page. 对同一页面的后续请求只是调用页面的运行时servlet。 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。

JSF : JSF:

JavaServer Faces is a standard Java framework for building user interfaces for Web applications. JavaServer Faces是用于为Web应用程序构建用户界面的标准Java框架。 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. 最重要的是,它简化了用户界面的开发,这通常是Web应用程序开发中比较困难和繁琐的部分之一。
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. 虽然可以通过使用基础Java Web技术(例如Java servlet和JavaServer Pages)来构建用户界面,而无需为企业Web应用程序开发设计全面的框架,但这些核心技术通常会导致各种开发和维护问题。 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. 更重要的是,当开发人员实现生产质量解决方案时,JSF解决的同一组问题将以非标准方式得到解决。 JavaServer Faces is designed to simplify the development of user interfaces for Java Web applications in the following ways: JavaServer Faces旨在通过以下方式简化Java Web应用程序用户界面的开发:
• It provides a component-centric, client-independent development approach to building Web user interfaces, thus improving developer productivity and ease of use. •它提供了一种以组件为中心,独立于客户端的开发方法来构建Web用户界面,从而提高了开发人员的工作效率和易用性。
• It simplifies the access and management of application data from the Web user interface. •它简化了Web用户界面对应用程序数据的访问和管理。
• 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. •它描述了Web应用程序的一组标准体系结构模式。

[ Source : Complete reference:JSF ] [ 来源: 完整参考:JSF ]


#5楼

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技术是Java技术系列的一部分。 JSP pages are compiled into servlets and may call JavaBeans components (beans) or Enterprise JavaBeans components (enterprise beans) to perform processing on the server. JSP页面被编译为servlet,可以调用JavaBeans组件(bean)或Enterprise JavaBeans组件(企业bean)来在服务器上执行处理。 As such, JSP technology is a key component in a highly scalable architecture for web-based applications. 因此,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技术是一个用于构建Web应用程序用户界面的框架。 JavaServer Faces technology includes: 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. JavaServer Pages(JSP)自定义标记库,用于在JSP页面中表示JavaServer Faces接口。

JSP is a specialized kind of servlet. JSP是一种特殊的servlet。

JSF is a set of tags you can use with JSP. JSF是一组可以与JSP一起使用的标记。


#6楼

JSP (JavaServer Pages) 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是在服务器上运行的Java视图技术 ,它允许您使用客户端语言(如HTML,CSS,JavaScript等)编写模板文本。 JSP supports taglibs , which are backed by pieces of Java code that let you control the page flow or output dynamically. JSP支持taglibs ,它由Java代码支持,允许您动态控制页面流或输出。 A well-known taglib is JSTL . 一个着名的taglib是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还支持表达式语言 ,可用于访问后端数据(通过页面中可用的属性,请求,会话和应用程序范围),主要与taglib结合使用。

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. 当第一次请求JSP或Web应用程序启动时,servlet容器会将其编译为扩展HttpServlet的类,并在Web应用程序的生命周期内使用它。 You can find the generated source code in the server's work directory. 您可以在服务器的工作目录中找到生成的源代码。 In for example Tomcat , it's the /work directory. 例如Tomcat ,它是/work目录。 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请求中,servlet容器将执行已编译的JSP类,并通过网络将生成的输出(通常只是HTML / CSS / JS)通过网络发送到客户端,然后客户端将其显示在Web浏览器中。

Servlets Servlet的

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. Servlet是在服务器计算机上运行的Java应用程序编程接口(API) ,它拦截客户端发出的请求并生成/发送响应。 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 . 一个众所周知的例子是HttpServlet ,它提供了使用流行的HTTP方法 (如GETPOST挂钩HTTP请求的方法 You can configure HttpServlet s to listen to a certain HTTP URL pattern, which is configurable in web.xml , or more recently with Java EE 6 , with @WebServlet annotation. 您可以将HttpServlet配置为侦听某个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. 首次请求Servlet或在Web应用程序启动期间,servlet容器将创建它的实例并在Web应用程序的生命周期内将其保留在内存中。 The same instance will be reused for every incoming request whose URL matches the servlet's URL pattern. 对于其URL与servlet的URL模式匹配的每个传入请求,将重用相同的实例。 You can access the request data by HttpServletRequest and handle the response by HttpServletResponse . 您可以通过访问请求数据HttpServletRequest和处理由响应HttpServletResponse Both objects are available as method arguments inside any of the overridden methods of HttpServlet , such as doGet() and doPost() . 这两个对象都可以作为HttpServlet任何重写方法中的方法参数使用,例如doGet()doPost()

JSF (JavaServer Faces) 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 . JSF是一个基于组件的MVC框架 ,它构建在Servlet API之上,并通过taglibs提供组件 ,可以在JSP或任何其他基于Java的视图技术(如Facelets)中使用 Facelets is much more suited to JSF than JSP. Facelets比JSP更适合JSF。 It namely provides great templating capabilities such as composite components , while JSP basically only offers the <jsp:include> for templating in JSF, so that you're forced to create custom components with raw Java code (which is a bit opaque and a lot of tedious work) when you want to replace a repeated group of components with a single component. 它提供了很好的模板功能,例如复合组件 ,而JSP基本上只提供了用于模板化的<jsp:include> ,因此您不得不使用原始Java代码创建自定义组件(这有点不透明和很多当你想用一个组件替换一组重复的组件时,这是一项繁琐的工作。 Since JSF 2.0, JSP has been deprecated as view technology in favor of Facelets. 从JSF 2.0开始,JSP已被弃用为视图技术而转而支持Facelets。

Note : JSP itself is NOT deprecated, just the combination of JSF with JSP is deprecated. 注意 :不推荐使用JSP本身,不推荐使用JSF与JSP的组合。

Note : JSP has great templating abilities by means of Taglibs, especially the ( Tag File ) variant. 注意 :JSP通过Taglibs具有很强的模板功能,尤其是( Tag File )变体。 JSP templating in combination with JSF is what is lacking. JSP模板与JSF结合是缺乏的。

As being a MVC ( Model-View-Controller ) framework, JSF provides the FacesServlet as the sole request-response Controller . 作为MVC( 模型 - 视图 - 控制器 )框架,JSF提供FacesServlet作为唯一的请求 - 响应控制器 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. 它需要您手中的所有标准和繁琐的HTTP请求/响应工作,例如收集用户输入,验证/转换它们,将它们放入模型对象,调用操作和呈现响应。 This way you end up with basically a JSP or Facelets (XHTML) page for View and a JavaBean class as Model . 通过这种方式,您最终可以获得View的JSP或Facelets(XHTML)页面以及作为Model的JavaBean类。 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. JSF组件用于将视图与模型绑定(例如ASP.NET Web控件), FacesServlet使用JSF组件树完成所有工作。

Related questions 相关问题

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
JSF是一种用于构建Java Web 应用程序的标准框架(是Java Community Process 规定的JSR-127标准)。JSF(Java Server Faces)技术为开发基于网络用户界面的Java开发者提供了标准的编程接口API以及标签库。就像Struts框架一样,JSF定义了一套JSF标签 JSF的全称   1、Joint Strike Fighter (JSF)   2、Java Server Faces (JSF) Java Server Faces (JSF)   JSF是一种用于构建Java Web 应用程序的标准框架(是Java Community Process 规定的JSR-127标准)。它提供了一种以组件为中心的用户界面(UI)构建方法,从而简化了Java服务器端应用程序的开发。由于由Java Community Process (JCP) 推动,属于Java EE 5中的技术规范,而受到了厂商的广泛支持。   JSF(Java Server Faces)技术为开发基于网络用户界面的Java开发者提供了标准的编程接口API以及标签库。就像Struts框架一样,JSF定义了一套JSF标签,能够生成与JavaBean属性绑定在一起的HTML表单元素。从应用开发者的角度看,两种框架十分相似,但是JSF可能会得到更多的支持,因为JSFJava的标准。在未来的发展中,可能所的J2EE应用服务器都需要支持JSFJava Server Faces技术好处   引入了基于组件事件驱动的开发模式,使开发人员可以使用类似于处理传统界面的方式来开发Web应用程序。提供了行为与表达的清晰分离。 不用特别的脚本语言或者标记语言来连接UI组件Web层。JSF技术API被直接分层在Servlet API的顶端。 技术为管理组件状态提供一个丰富的体系机构、处理组件数据、确认用户输入操作事件。 Java Server Faces应用程序   典型的JSF应用程序包含下列部分:   一组JSP页面   一组后台bean(为在一个页面上的UI组件定义的属性函数的JavaBean组件)   应用程序配置资源文件(定义页面导航规则、配置bean其它的自定义对象,如自定义组件)   部署描述文件( web.xml )   一组由应用程序开发者创建的自定义对象(可能)   一些可能包含自定义组件、约束、转换器或者监听器的对象   为在页面中表现自定义对象的一组自定义tag   包含JSP页面的JSF应用程序也使用由为了表现UI组件在页面上的其他对象的JSF技术而定义的标准的tag库。 Java Server Faces技术的重要开发框架 sun-ri、myfaces、icefaces、richfaces、seam
©️2022 CSDN 皮肤主题:1024 设计师:我叫白小胖 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值