Datasheet
This time we used the getNamedDispatcher method with the name of our servlet in order to get a
PortletRequestDispatcher. This is another important point to consider if you choose to do the
following:
String reqPath = “/calView.jsp?user=Jennifer”;
PortletRequestDispatcher prd = portContext.getRequestDispatcher(reqPath);
prd.include(req, resp);
Because the parameter user is specified in the query string, it will take precedence over any other ren-
der
parameters named user being passed to the JSP. You probably will not encounter this problem, but
it is something to keep in the back of your mind in case you run into crazy behaviors: specifying a query
string takes precedence over other parameters.
There are restrictions on the use of
HttpServletRequest. These methods are not available to the
included servlet or JSP:
❑
getProtocol
❑ getRemoteAddr
❑ getRemoteHost
❑ getRealPath
❑ getRequestURL
❑ getCharacterEncoding
❑ setCharacterEncoding
❑ getContentType
❑ getInputStream
❑ getReader
❑ getContentLength
These methods will all return null (getContentLength returns zero) if invoked from a servlet or JSP
that has been included by a
PortletRequestDispatcher. Depending on how you create your
PortletRequestDispatcher, you may not have access to other methods. These additional methods
are not available to servlets or JSPs accessed from a
PortletRequestDispatcher created by calling
getNamedDispatcher:
❑
getPathInfo
❑ getPathTranslated
❑ getServletPath
❑ getRequestURI
❑ getQueryString
The reason why the preceding methods would be unavailable through getNamedDispatcher is pretty
simple: Because you didn’t use a path for your request, there is no data with which these fields can be
20
Chapter 1
04 469513 Ch01.qxd 1/16/04 11:04 AM Page 20