views:

676

answers:

3

i am asked to work on portlets and portals. i want to know the difference between a portlet and a servlet ? how/where does a portlet differ(may be functionally) from servlet ?

A: 

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

whatnick
+1  A: 

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.

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.

djna
+2  A: 

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 two standards they differ in containers, APIs, life cycle, deployment, etc.

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) has to respond to two types of actions: render and request. There are of course more to it but I thought this is the core difference between the two when I studied portal development.

grigory