11.2.3 PortletRequestDispatcher.include

The include() method of the PortletRequestDispatcher class is used to include JSPs and servlets. The RenderRequest and RenderResponse objects passed into the render method must be passed into the include() method.

The include() method can be called at any time during the render method of the portlet.

Note: The included JSPs and Servlets should not use the Servlet RequestDispatcher to do a forward as this may cause unpredictable behavior.

JSPs and Servlets called from the include method will have access to the following request parameters. However, if the RequestDispatcher for a servlet was obtained using the getNamedDispatcher the following attributes will not be available.

All of the following attribute and parameter can be obtained from the requests getAttribute method.

The following five request parameters have corresponding methods in the HttpServletRequest to get the information.

 

javax.servlet.include.request_uri

The request_uri is the context root relative path of the included JSP or servlet

 

javax.servlet.include.context_path

The context_path in the context root for the portlet.

 

javax.servlet.include.servlet_path

The servlet path will be the request_uri minus the context_path

 

javax.servlet.inclue.path_info

path_info contains information about the path.

 

javax.servlet.include.query_string

The query_string will contain any parameters that have been added to the path. For example if you had a path of /mypath/myjsps.jsp?name=Hailey, the query_string would contain name=Hailey.

The following three attributes will store portlet objects. When using JSPs it is recommended that you use the defineObjects portlet tags rather than getting the objects from the request.

Example 11-5 Request attributes

RenderRequest renderRequest   = (RenderRequest)request.getAttribute("javax.portlet.request");
RenderResponse renderResponse = (RenderResponse)request.getAttribute("javax.portlet.response");
PortletConfig portletConfig   = (PortletConfig)request.getAttribute("javax.portlet.config");

 

javax.portlet.config

Is an object of type PortletConfig

 

javax.portlet.request

Is an object of type RenderRequest

 

javax.portlet.response

Is an object of type RenderResponse


Redbooks
ibm.com/redbooks