Saturday 22 October 2011

Similarities and Differences between Portlets and Servlets..

This post is about to understand the differences and similarities of portlet and servlet. 

The differences between the portlet and servlet are:
1. Servlets can provide the content to complete web pages, whereas portlets only provide fragments. And these fragments are then aggregated to form a complete web page by the portal.
2. The user cannot access a portlet directly using a URL in the way that a servlet is accessed. Instead, the URL points to the page containing all of the portlets on single page.
3. Portlets aren’t allowed to generated HTML code that contains tags such as base, body, frame, frameset, head, title or html . Note: Here the iframe tag can be used with caution.
4. The communication between the web client and the portlets is performed through the portal.
5. Portlet allows to manipulate the portlets’ window states or portlet modes by providing the buttons or controls.
6. Portlets support two scopes within the session; application scope and portlet scope but servlets not.

The similarities between the servlet and portlet:
1. Servlets and portlets are web based components that utilize Java for their implementation.
2. Portlets are managed by a portlet container similar to a servlet container.
3. Both of these components generate content, which can be static or dynamic.
4. Both portlets and servlets have a lifecycle that is controlled by the container.
5. The client/server model is used for both servlets and portlets.
6. The packaging and deployment are essentially the same.
7. The manner in which the classes are loaded and the class loaders that perform the work are also the same.
8. Lifecycle management is similar.
9. The Request and Response semantics are also similar.

There are several things that servlets are allowed to do, but portlets are not allowed. These are:
1. Portlet aren’t allowed to set the character set encoding of the response.
2. Portlet also aren’t allowed to set the HTTP headers on the response.
3. Portlet cannot manipulate the URL of the client request to the portal.

Enjoy:)

1 comment: