Portlet and Servlet


Similarities with servlets
  •   Portlets are Java technology based web components
  •  Portlets are managed by a specialized container
  •   Portlets generate dynamic content
  •  Portlets lifecycle is managed by a container
  •  Portlets interact with web client via a request/response paradigm 
Portlet vs Servlet
  • Portlets only generate markup fragments in the render method, not complete documents. The Portal aggregates portlet markup fragments into a complete portal age
  •  Portlets can only be invoked through URLs constructed via the portlet API.
  •  Web clients interact with portlets through a portal system
  •   Portlets have more refined request handling, i.e. action requests, event request,render request and resource requests
  • Portlets have predefined portlet modes and window states that indicate the function the portlet is performing and the amount of real estate in the portal page
  • Portlets can exist many times in a portal page
Special  functionality  of a Portlet
  • Portlets have a means of accessing and storing persistent configuration and customization data
  •  Portlets have access to user profile information
  •  Portlets have URL rewriting functions for creating hyperlinks within their content, which allow portal server agnostic creation of links and actions in page fragments
  • Portlets can store transient data in the portlet session in two different scopes: the application-wide scope and the portlet private scope.
  •  Portlets can send and receive events from other portlets or can receive container defined events.
Functionality not supported by a Portlet
  • Setting the character set encoding of the render response
  • The URL of the client request to the portal 
Sharing between Portlet and Servlet
  • Portlets, servlets and JSPs are bundled in an extended web application called a portlet application. Portlets, servlets and JSPs within the same portlet application share the classloader, application context and session.
  • A portlet can call servlets and JSPs just like a servlet can invoke other servlets and JSPs using a request dispatcher
  • When a servlet or JSP is called from within a portlet, the servlet request given to the servlet or JSP is based on the portlet request and the servlet response given to the servlet or JSP is based on the portlet response.
  • Attributes set in the portlet request are available in the included servlet request
  • The portlet and the included servlet or JSP share the same output stream
  • Attributes set in the portlet session are accessible from the servlet session and vice versa
  • The lifecycle of the PortletContext is tied to the SevletContext of this web application and the attributes set in the PortletContext are mirrored in the ServletContext. The lifecycle of the PortletSession is tied to the HttpSession of this web application and the attributes set in the PortletSession are mirrored in the HttpSession. Due to this fact the servlet lifecycle listeners for ServletContext and HttpSession can also be used for notifications on the PortletContext and PortletSession operations.