Portlets Classes

The Common classes of the Portlet API are:

  1. PortletRequest
  2. PortletResponse
  3. PortletURI
  4. PortletConfig
  5. PortletContext


This is the equivalent of javax.servlet.ServletRequest.
The PortletRequest provide the following informations:

Attributes are name/value pairs associated with a request. Attributes are available only for the scope of the request. The portlet can get, set, and remove attributes during one request.
Parameters are name/value pairs sent by the client in the URI query string as part of a request. Often the parameters are posted from a form. Parameters are available for the scope of a specific request. The portlet can get but not set parameters from a request.
User data
The PortletData object represents user-specific portlet data that is saved to persistent store. For example, a user can set a portlet e-mail application to check for new mail every 30 minutes. This preference is stored for the user in the PortletData object.
The user data are obtained via
The PortletSetting object configuration data of a portlet that are shared amongs all the users.
The user data are obtained via PortletRequest.getSettings()
The PortletSession object contains a user's data for more than one request. In contrast with the request, which does not retain data after the request is completely processed, session attributes can be retained for more than one request.
The Session is obtained via PortletRequest.getPortletSession()
Portlet.Mode provides the current or previous mode of the portlet.
The Mode is obtained via PortletRequest.getMode()
The PortletWindow object represents the state of the current portlet window. The portlet can access this object to determine if the portlet is currently maximized or not.
The Window is accessed via PortletRequest.getWindow()
The Client object encapsulates request-dependent information about the user agent of a specific request. The Client is obtained via PortletRequest.getClient()
The following information can be obtained from the client:
User Agent
The portlet can get the String sent by the user agent to identify itself to the portal
The Markup
The Portlet.Markup that indicates the markup language that the client supports
The MIME type
The portlet can get the String that indicates the MIME types supported by the client (for example: text/vnd.wap.wml)
The Manufacturer
The manufacturer of the client device
The Version
The version of the client device


This is the equivalent of javax.servlet.ServletResponse.
The PortletResponse encapsulates information to be returned from the server to the client. PortletResponse is accessed using the
a Portlet.service() method and is used by the portlet to return output to the client. The PortletResponse also includes methods for creating PortletURI objects or qualifying portlet markup with the portlet's namespace.


The PortletURI object contains a URI pointing to the portlet instance and can be further extended by adding portlet-specific parameters and by attaching mode, state or an action.
PortletURI are used for:


This is the equivalent of javax.servlet.ServletConfig.
The PortletConfig provides a Portlet with its configuration. The PortletConfig is read from the Portlet Deployment Descriptor.
The PortletConfig provide access to the Portlet's initialization parameters set in the deployment descriptor and to the PortletContext


This is the equivalent of javax.servlet.ServletContext.
The PortletContext interface defines a portlet's view of the portlet container within each portlet is running
The PortletContext provide the following informations:

Attributes are name/value pairs available for the complete lifecycle of a portlet. The portlet can get, set and remove attributes. Attributes of the context are shared amongs all the portlets of the web application.
It is through the PortletContext that a portlet can load or include resources located in the portlet's application scope. Available methods are PortletContext.include() and PortletContext.getResourceAsStream().
The include() method is typically used to invoke .html, .xml, .txt or .vm (Velocity) files
Important: .jsp files not supported
Localized text
The PortletContext.getText() method is used by the portlet to access resource bundles within a given locale.
The PortletLog provide the portlet the ability to log information, warning or error messages.
The PortletService object allow portlets to uses pluggable services.