Monday 6 May 2013

Comparing Servlets and Portlets Part 3 : Portlet deployment descriptor file


In the last article we saw how a RequestDispatcher works for both Servlets and Portlets.

Difference between a web and a portlet application.

A basic web application will have a web.xml file, Servlet classes and JSP's. The web.xml file helps to configure the Servlets which make the application. It helps a developer to define which URL's will be handled by which Servlets. How security will be applied to these URL's, session management etc.



A Portlet application will have a portlet.xml file in addition to web.xml file. Portlet XML file helps a developer to define the Portlets which make that application.

Now lets compare a web.xml and a portlet.xml file.

A web.xml file:


------------------

HelloWorldServlet
com.HelloWorld


HelloWorldServlet
*.do

------------------


Now a portlet.xml file:



HelloWorldPortlet
com.HelloWorldPortlet



A web.xml has definition. In portlet.xml we do not define any URL mappings. Reason being Portlets are applications which can be added to any page in addition to other Portlets. That's why there is a concept of Portlet URL. These URL's are generated by the Portlet itself and help to direct the request to same servlet.
Action URL and Render URL for example can be used to create URL's. ActionURL will help generate an Action Request, similar to what doPost does in Servlets. RenderURL is for a render request like the doGet in Servlets.

Example: PortletURL refreshURL = response.createRenderURL(); // response being a RenderResponse object

In addition to this basic configuration a portlet.xml can be used to define the init-params and resource bundle also.

No comments:

Post a Comment