JSF和JSP的区别

来源:互联网 发布:淘宝产品经理 编辑:程序博客网 时间:2024/05/01 07:31

在Eclipse的Help上有这样一段描述JSP文件的内容:

The JavaServer Pages technology enables you to generate dynamicweb content, such as HTML, DHTML, XHTML, and XML files, to includein a Web application. JSP filesare one way to implement server-side dynamic pagecontent. JSP files allow a Webserver, such as Apache Tomcat, to add content dynamically to yourHTML pages before they are sent to a requesting browser.

另外有一处介绍了JSP的典型应用:

A JSP page is ideal for tasksthat are better suited to execution on the server, such asaccessing databases or calling Enterprise Java™ beans。

JSP technologn enables Web developers and designers to rapidlydevelop and easily maintain, information-rich, dynamic Web pagesthat leverage existing business systems. As part of the Javatechnology family, JSP technology enables rapid development ofWeb-based applications that are platform independent. JSPtechnology separates the user interface from content generation,enabling designers to change the overall page layout withoutaltering the underlying dynamic content.

可见JSP是服务器端展现动态网页内容的一种技术。

而对于JSF,Sun在2006年正式把JSF由幕后推到前台,正式纳入J2EE5.0规范。有如下段落:

JavaServer   Faces  technology   includes:

* A set of APIs for representing UI components andmanaging their state, handling events and input validation,defining page navigation, and supporting internationalization andaccessibility.

* A  JavasServerPages(JSP) custom tag library for expressing a JavaServer Facesinterface within a JSP page.

由此可看出,JSF是UI组件状态,处理事件等的标准化方式。JSF是一种技术,同时笔者认为更是一种框架。与许多的Web框架一样,都会有自已的config.xml即faces-config.xml。而JSP则是表现层,借助于JSP即可表现Web应用的界面效果,而JSF则是表现层框架,与此类似Struts也是表现层框架,虽然性质不同但也殊途同归。

JSF是一个标准的服务器端架构,用于简化网络应用软件表示层的构建。开发人员可以组装这些可复用的用户界面组件来创建网页,将这些组件绑定到应用程序的数据源,并利用服务器端的事件处理器来处理客户端事件。依据JSF规范,组件开发者所制作的组件可以简洁地整合到JSF运行时架构,而且在应用软件设计过程中,还可以整合到与JSF兼容的集成开发环境中。JSR127规范定义了这样的JSF架构,还同时提供了比如输入栏和按钮等基本用户界面组件的可供参考的实现。JSF组件中的绝大部分都符合HTML2.0标准中的HTML组件和标签的规范。这些相对简单的组件对于很多网络应用程序来讲已经足够了。

JSF框架的主要优势之一就是它既是   Java  Web  用户界面标准又是严格遵循模型-视图-控制器  (MVC)  设计模式的框架。用户界面代码(视图)与应用程序数据和逻辑(模型)的清晰分离使  JSF  应用程序更易于管理。为了准备提供页面对应用程序数据访问的  JSF  上下文和防止对页面未授权或不正确的访问,所有与应用程序的用户交互均由一个前端“Faces”servlet(控制器)来处理。

原创粉丝点击