Portlet programming guidelines #1 - Understanding Portlets & Servlets in Java EE
In this series of blog entries, I will share a few programming guidelines that I, as portlet programmer, have learnt the hard way. I hope someone finds these useful :)
Understanding Portlets & Servlets in Java EEThe most common mistake that newbie portlet programmers make is to consider portlets as equivalents to servlets.Though the resemblance between the Portlet API and the Servlet API is more than a coincidence, portlets are different beasts that deserve their own special treatment.
The similarities between the two APIs allow servlet programmers to rapidly get to speed with portlets. The differences, however, confuse them. So let's attack the problem first. How are servlets different from portlets ?
A servlet is typically a full blown application by itself. A portlet is *never* a full fledged application by itself. Portlets are applicationlets in that they are always part of a larger application - The Portal.
This is an important distinction that needs to be kept in mind. In fact, this can answer most questions that beginners have about portlets:
Q: Why is it not possible to acesses the content of a portlet using
a unique URL ?
A: Because the portlet is not an application by itself, but a part of a larger application.
Q:Why is it not possible to setCharacter encoding within a portlet ?
A:Because the portlet is not an application by itself, but a part of a larger application.
Q:Why is it not possible to forward the request to a servlet within a portlet ?
A:Because the portlet is not an application by itself, but a part of a larger application.
... and so on.
There are many other differences one could enumerate between portlets and servlets but all those are a result of this fundamental difference.
Moving on to the similarities, If you are a servlet programmer you will find that the portlet spec is to a large extent similar to the servlet spec in terms of the APIs and programming models. This is intentional. The portlet APIs have been intentionally designed to "mimic" the servlet API.
Without digressing too much, there was even a school of thought that felt that portlets were logical extensions to servlets. However, it was realized that describing portlets as an "extensions" to servlets was not good enough to clearly define it's behavior.
Therefore today we have two different components - portlets and servlets. Similar but not the same.In most web applications that you encounter in the future, you can expect to find both servlet and portlet components to co-exist. The former would define how a web application would behave as a standalone application. The latter would define how the application would behave when it is plugged into a larger application, the portal.
Posted at 12:41AM Apr 19, 2006 by Navaneeth Krishnan in Portlet |
This work is licensed under a
Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License.