Show TOC Start of Content Area

Background documentation Dispatching Requests to Servlets and JSPs  Locate the document in its SAP Library structure

Portlets can dispatch requests to servlets and JSPs, that is, include servlets and JSPs to generate markup fragments. Portlets cannot include other portlets or forward requests to other portlets. Servlets and JSPs included from portlets should not use the servlet RequestDispatcher forward method as its behavior may be non-deterministic. Using the dispatching mechanism, portlets support the Model-View-Controller pattern. For example, a portlet can act as a controller, fill a bean with data, and include a JSP page to render the output.

You may use a PortletRequestDispatcher object only when executing the render method of the Portlet interface. To obtain a PortletRequestDispatcher object, you use one of the following methods of the PortletContext object:

       getRequestDispatcher

This method takes a String argument describing a path within the scope of the PortletContext of a portlet application. The path begins with a / (forward slash) and is relative to the PortletContext root.

       getNamedDispatcher

Example

The following code shows how a portlet uses a JSP:

String path = "/employeeData.jsp?employeeID=1";

PortletContext context = getPortletContext();

PortletRequestDispatcher prd = context.getRequestDispatcher(path);

prd.include(renderRequest, renderResponse);

 

 

End of Content Area