I am asked to work on portlets and portals.
我被要求在portlet和门户上工作。
I want to know the difference between a portlet and a servlet?
我想知道portlet和servlet之间的区别吗?
How / where does a portlet differ (may be functionally) from a servlet?
portlet(在功能上)与servlet有何不同?
5 个解决方案
#1
55
Portlets are part of JSR-168 standard that regulates portal containers and components. This is different standard from standards for web containers (and servlets). Though there are definitely strong parallels between these two standards they differ in containers, APIs, life cycle, configuration, deployment, etc.
portlet是JSR-168标准的一部分,该标准规范门户容器和组件。这与web容器(和servlet)的标准不同。尽管这两种标准之间存在明显的相似之处,但它们在容器、api、生命周期、配置、部署等方面存在差异。
The main difference between portlet vs. servlet could be that while servlet always responds to single type of action - request, portlet (due to nature of its life cycle and stronger container bindings) has to respond to two types of actions: render and request. There are of course more to it but I found this as the core difference between the two when I studied portal development.
portlet与servlet的主要区别在于,虽然servlet总是响应单一类型的操作——请求,但portlet(由于其生命周期的性质和更强的容器绑定)必须响应两种类型的操作:呈现和请求。当然还有更多内容,但我在研究门户开发时发现这是两者之间的核心区别。
#2
115
Enhanced from Source: Servlets Vs Portlets
源代码增强:servlet Vs portlet
Similarities
相似之处
Servlets and Portlets are web based components which use Java for their implementation.
servlet和portlet是基于web的组件,它们的实现使用Java。
Portlets are managed by a portlet container just like servlet is managed by servlet container.
portlet由portlet容器管理,就像servlet容器管理servlet一样。
Both static and dynamic content can be generated by Portlets and Servlets.
静态和动态内容都可以由portlet和servlet生成。
The life cycle of portlets and servlets is controlled by the container
portlet和servlet的生命周期由容器控制
The client/server model is used for both servlets and portlets
客户机/服务器模型用于servlet和portlet
The packaging and deployment are essentially the same, WAR/EARs.
包装和部署基本上是相同的,WAR/ ear。
Application Session exists in both Servlet and Portlet containers. It is one of the ways of of sharing data (crude Inter-Portlet Communication) from the render phase to the action phase (or any lower phases) in the portlet containers.
应用程序会话存在于Servlet和Portlet容器中。它是共享数据(粗portlet间通信)的一种方式,从呈现阶段到portlet容器中的操作阶段(或任何较低的阶段)。
- Both Servlets and Portlets use similar server / VM environments that support it. Although, some additional configurations might needed in case of portlets to make it tick
- servlet和portlet都使用支持它的类似服务器/ VM环境。尽管如此,在portlet的情况下可能需要一些额外的配置。
- The build/DI tools are similar for both - Ant, Maven, Gradle, etc are all supported. Mostly :) - This has changed a bit with Liferay 7.
- 构建/DI工具对于Ant、Maven、Gradle等都是类似的。大多数情况下:)-这一点在Liferay 7上有所改变。
Dissimilarities
相异
Servlets can render complete web pages, whereas portlets renders html fragments. These fragments are aggregated by the portal into a complete web page.
servlet可以呈现完整的web页面,而portlet则呈现html片段。门户将这些片段聚合为一个完整的web页面。
The content type of JSR 168 portlets can be only cHTML, XHTML, WML. It does not support other content types.
JSR 168 portlet的内容类型只能是cHTML、XHTML和WML。它不支持其他内容类型。
Portlets are not allowed to generate HTML code that contains tags such as body, frame, frameset, head, html, or title.
portlet不允许生成包含标签的HTML代码,如body、frame、frameset、head、HTML或title。
A Portlet unlike a servlet doesn’t have URL attached to it so it cannot be accessed directly. Access is only through the portal page which holds the portlet.
与servlet不同的Portlet没有附加URL,因此不能直接访问它。访问只能通过保存portlet的门户页面进行。
Portlets can be provided with controls to manipulate its window states or portlet modes.
portlet可以提供控件来操作其窗口状态或portlet模式。
Multiple instances of a single portlet can be placed onto the same page.
单个portlet的多个实例可以放在同一个页面上。
Portlets support persistent configuration and customization, profile information.
portlet支持持久性配置和定制,概要信息。
Portlets can have two types of request viz. render request and action request.
portlet可以有两种请求类型,即呈现请求和操作请求。
Portlets have two scopes within session; application scope for communication across portlets and portlet scope for intra portlet communication.
portlet在会话中有两个作用域;用于portlet间通信的应用程序范围和用于portlet内部通信的portlet范围。
Portlet cannot set the character set encoding of the response nor can it set the HTTP response headers.
Portlet不能设置响应的字符集编码,也不能设置HTTP响应头。
Portlets doesn’t have access to request URL. So it cannot access the query parameters appended to the URL. Portlets cannot set cookies.
portlet没有访问请求URL的权限。因此它无法访问附加到URL的查询参数。portlet不能设置cookie。
Typical methods of Portlet API are
doView()
,doEdit()
,doHelp()
andprocessAction()
while those of servlet areservice()
,doPost()
,doGet()
.Portlet API的典型方法是doView()、doEdit()、doHelp()和processAction(),而servlet的这些方法是service()、doPost()、doGet()。
Deployment of Portlets involves different approach than a Servlet application. Some Providers (Liferay/Alfresco/WebSphere) support hot-deploying of portlets without the need to restart the server which is not possible in case of servlets without modularizing the application using special libraries such as OSGi.
portlet的部署涉及的方法与Servlet应用程序不同。一些提供程序(Liferay/Alfresco/WebSphere)支持portlet的热部署,而不需要重新启动服务器,这在使用特定库(如OSGi)模块化应用程序时是不可能的。
Edit (From comments)
编辑(评论)
A Portlet container is built on a Servlet container. So ultimately it can be said that the portlet runs on a Servlet Container. But while developing apps, we view a portlet container separately from the Servlet/Java EE container.
Portlet容器构建在Servlet容器之上。因此,最终可以说portlet在Servlet容器上运行。但是,在开发应用程序时,我们会从Servlet/Java EE容器中单独查看portlet容器。
#3
7
Both portlets and servlets receive an http request and return a response, which is usally some HTML that can be rendered by a browser. A portlet is used in the context of a "Portal", the idea being that a single page seen by the user has lots of parts, think tiles, each coming from a different portlet.
portlet和servlet都接收一个http请求并返回一个响应,这是一个可以由浏览器呈现的HTML。portlet是在“门户”上下文中使用的,其思想是用户看到的单个页面有许多部分,每个部分都来自不同的portlet。
Now, you can get that "tiled" effect from normal servets (See Struts + Tiles for an example of how) the extra bit from the portlets is that the portlets are in a richer environment provided by the Portal, extra APIs are provided so that what is displayed by any portlet can be configured by individual users to their preferences, and the porlets can communicate with each other - press a button in one, something happens in a another.
现在,您可以得到“瓷砖”效应从正常servets(见Struts +的瓷砖为例)的额外portlet的portlet提供的更丰富的环境门户,提供额外的api,这样所显示的任何portlet可以配置用户个人偏好,和porlets可以相互沟通,按下一个按钮在一个发生在另一个地方。
#4
6
Servlets have a java definition (applications which handle HTTP GET/POST requests), while portlets have a user interface definition.A component performing a specific function similar to the windows vista widgets or a lot of components used in * here. They need not necessarily be backed by servlets on the server side. But the Portlet standard was developed alongside java. O'Reilly has a nice tutorial.
servlet有一个java定义(处理HTTP GET/POST请求的应用程序),而portlet有一个用户界面定义。执行特定功能的组件,类似于windows vista小部件或*中使用的许多组件。它们不一定需要服务器端的servlet来支持。但是Portlet标准是与java一起开发的。O'Reilly有一个很好的教程。
#5
4
Essentially, Servlets provide content that normally takes up the whole page in a browser (unless you're using frames), and portlets provide content that is wrapped by a window. With portlets, you can have multiple portlets side by side with one another and each one can provide content and functionality that is different from the other. A portlet can provide the complete interaction for one type of application, while another portlet can provide content for another type of application. The portal can provide some house keeping functionality and secured single point of entry to all of the portlets on a page. As for the particulars (similarities/differences) between them, please continue reading. Here are some similarities: Servlets and portlets are web based components that utilize Java for their implementation Portlets are managed by a portlet container similar to a servlet container Both of these components generate content, which can be static or dynamic
本质上,servlet提供的内容通常占据浏览器中的整个页面(除非您使用框架),portlet则提供由窗口包装的内容。对于portlet,您可以同时拥有多个portlet,每个portlet可以提供不同于其他portlet的内容和功能。portlet可以为一种应用程序类型提供完整的交互,而另一种portlet可以为另一种应用程序类型提供内容。门户可以为页面上的所有portlet提供一些房屋保留功能和安全单点。关于他们之间的细节(相似/不同),请继续阅读。这里有一些相似之处:servlet和portlet是基于web的组件,它们利用Java来实现它们的实现portlet,它们由一个类似于servlet容器的portlet容器管理,这两个组件都生成内容,可以是静态的,也可以是动态的。
#1
55
Portlets are part of JSR-168 standard that regulates portal containers and components. This is different standard from standards for web containers (and servlets). Though there are definitely strong parallels between these two standards they differ in containers, APIs, life cycle, configuration, deployment, etc.
portlet是JSR-168标准的一部分,该标准规范门户容器和组件。这与web容器(和servlet)的标准不同。尽管这两种标准之间存在明显的相似之处,但它们在容器、api、生命周期、配置、部署等方面存在差异。
The main difference between portlet vs. servlet could be that while servlet always responds to single type of action - request, portlet (due to nature of its life cycle and stronger container bindings) has to respond to two types of actions: render and request. There are of course more to it but I found this as the core difference between the two when I studied portal development.
portlet与servlet的主要区别在于,虽然servlet总是响应单一类型的操作——请求,但portlet(由于其生命周期的性质和更强的容器绑定)必须响应两种类型的操作:呈现和请求。当然还有更多内容,但我在研究门户开发时发现这是两者之间的核心区别。
#2
115
Enhanced from Source: Servlets Vs Portlets
源代码增强:servlet Vs portlet
Similarities
相似之处
Servlets and Portlets are web based components which use Java for their implementation.
servlet和portlet是基于web的组件,它们的实现使用Java。
Portlets are managed by a portlet container just like servlet is managed by servlet container.
portlet由portlet容器管理,就像servlet容器管理servlet一样。
Both static and dynamic content can be generated by Portlets and Servlets.
静态和动态内容都可以由portlet和servlet生成。
The life cycle of portlets and servlets is controlled by the container
portlet和servlet的生命周期由容器控制
The client/server model is used for both servlets and portlets
客户机/服务器模型用于servlet和portlet
The packaging and deployment are essentially the same, WAR/EARs.
包装和部署基本上是相同的,WAR/ ear。
Application Session exists in both Servlet and Portlet containers. It is one of the ways of of sharing data (crude Inter-Portlet Communication) from the render phase to the action phase (or any lower phases) in the portlet containers.
应用程序会话存在于Servlet和Portlet容器中。它是共享数据(粗portlet间通信)的一种方式,从呈现阶段到portlet容器中的操作阶段(或任何较低的阶段)。
- Both Servlets and Portlets use similar server / VM environments that support it. Although, some additional configurations might needed in case of portlets to make it tick
- servlet和portlet都使用支持它的类似服务器/ VM环境。尽管如此,在portlet的情况下可能需要一些额外的配置。
- The build/DI tools are similar for both - Ant, Maven, Gradle, etc are all supported. Mostly :) - This has changed a bit with Liferay 7.
- 构建/DI工具对于Ant、Maven、Gradle等都是类似的。大多数情况下:)-这一点在Liferay 7上有所改变。
Dissimilarities
相异
Servlets can render complete web pages, whereas portlets renders html fragments. These fragments are aggregated by the portal into a complete web page.
servlet可以呈现完整的web页面,而portlet则呈现html片段。门户将这些片段聚合为一个完整的web页面。
The content type of JSR 168 portlets can be only cHTML, XHTML, WML. It does not support other content types.
JSR 168 portlet的内容类型只能是cHTML、XHTML和WML。它不支持其他内容类型。
Portlets are not allowed to generate HTML code that contains tags such as body, frame, frameset, head, html, or title.
portlet不允许生成包含标签的HTML代码,如body、frame、frameset、head、HTML或title。
A Portlet unlike a servlet doesn’t have URL attached to it so it cannot be accessed directly. Access is only through the portal page which holds the portlet.
与servlet不同的Portlet没有附加URL,因此不能直接访问它。访问只能通过保存portlet的门户页面进行。
Portlets can be provided with controls to manipulate its window states or portlet modes.
portlet可以提供控件来操作其窗口状态或portlet模式。
Multiple instances of a single portlet can be placed onto the same page.
单个portlet的多个实例可以放在同一个页面上。
Portlets support persistent configuration and customization, profile information.
portlet支持持久性配置和定制,概要信息。
Portlets can have two types of request viz. render request and action request.
portlet可以有两种请求类型,即呈现请求和操作请求。
Portlets have two scopes within session; application scope for communication across portlets and portlet scope for intra portlet communication.
portlet在会话中有两个作用域;用于portlet间通信的应用程序范围和用于portlet内部通信的portlet范围。
Portlet cannot set the character set encoding of the response nor can it set the HTTP response headers.
Portlet不能设置响应的字符集编码,也不能设置HTTP响应头。
Portlets doesn’t have access to request URL. So it cannot access the query parameters appended to the URL. Portlets cannot set cookies.
portlet没有访问请求URL的权限。因此它无法访问附加到URL的查询参数。portlet不能设置cookie。
Typical methods of Portlet API are
doView()
,doEdit()
,doHelp()
andprocessAction()
while those of servlet areservice()
,doPost()
,doGet()
.Portlet API的典型方法是doView()、doEdit()、doHelp()和processAction(),而servlet的这些方法是service()、doPost()、doGet()。
Deployment of Portlets involves different approach than a Servlet application. Some Providers (Liferay/Alfresco/WebSphere) support hot-deploying of portlets without the need to restart the server which is not possible in case of servlets without modularizing the application using special libraries such as OSGi.
portlet的部署涉及的方法与Servlet应用程序不同。一些提供程序(Liferay/Alfresco/WebSphere)支持portlet的热部署,而不需要重新启动服务器,这在使用特定库(如OSGi)模块化应用程序时是不可能的。
Edit (From comments)
编辑(评论)
A Portlet container is built on a Servlet container. So ultimately it can be said that the portlet runs on a Servlet Container. But while developing apps, we view a portlet container separately from the Servlet/Java EE container.
Portlet容器构建在Servlet容器之上。因此,最终可以说portlet在Servlet容器上运行。但是,在开发应用程序时,我们会从Servlet/Java EE容器中单独查看portlet容器。
#3
7
Both portlets and servlets receive an http request and return a response, which is usally some HTML that can be rendered by a browser. A portlet is used in the context of a "Portal", the idea being that a single page seen by the user has lots of parts, think tiles, each coming from a different portlet.
portlet和servlet都接收一个http请求并返回一个响应,这是一个可以由浏览器呈现的HTML。portlet是在“门户”上下文中使用的,其思想是用户看到的单个页面有许多部分,每个部分都来自不同的portlet。
Now, you can get that "tiled" effect from normal servets (See Struts + Tiles for an example of how) the extra bit from the portlets is that the portlets are in a richer environment provided by the Portal, extra APIs are provided so that what is displayed by any portlet can be configured by individual users to their preferences, and the porlets can communicate with each other - press a button in one, something happens in a another.
现在,您可以得到“瓷砖”效应从正常servets(见Struts +的瓷砖为例)的额外portlet的portlet提供的更丰富的环境门户,提供额外的api,这样所显示的任何portlet可以配置用户个人偏好,和porlets可以相互沟通,按下一个按钮在一个发生在另一个地方。
#4
6
Servlets have a java definition (applications which handle HTTP GET/POST requests), while portlets have a user interface definition.A component performing a specific function similar to the windows vista widgets or a lot of components used in * here. They need not necessarily be backed by servlets on the server side. But the Portlet standard was developed alongside java. O'Reilly has a nice tutorial.
servlet有一个java定义(处理HTTP GET/POST请求的应用程序),而portlet有一个用户界面定义。执行特定功能的组件,类似于windows vista小部件或*中使用的许多组件。它们不一定需要服务器端的servlet来支持。但是Portlet标准是与java一起开发的。O'Reilly有一个很好的教程。
#5
4
Essentially, Servlets provide content that normally takes up the whole page in a browser (unless you're using frames), and portlets provide content that is wrapped by a window. With portlets, you can have multiple portlets side by side with one another and each one can provide content and functionality that is different from the other. A portlet can provide the complete interaction for one type of application, while another portlet can provide content for another type of application. The portal can provide some house keeping functionality and secured single point of entry to all of the portlets on a page. As for the particulars (similarities/differences) between them, please continue reading. Here are some similarities: Servlets and portlets are web based components that utilize Java for their implementation Portlets are managed by a portlet container similar to a servlet container Both of these components generate content, which can be static or dynamic
本质上,servlet提供的内容通常占据浏览器中的整个页面(除非您使用框架),portlet则提供由窗口包装的内容。对于portlet,您可以同时拥有多个portlet,每个portlet可以提供不同于其他portlet的内容和功能。portlet可以为一种应用程序类型提供完整的交互,而另一种portlet可以为另一种应用程序类型提供内容。门户可以为页面上的所有portlet提供一些房屋保留功能和安全单点。关于他们之间的细节(相似/不同),请继续阅读。这里有一些相似之处:servlet和portlet是基于web的组件,它们利用Java来实现它们的实现portlet,它们由一个类似于servlet容器的portlet容器管理,这两个组件都生成内容,可以是静态的,也可以是动态的。