You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-user@portals.apache.org by Stephan Huber <sh...@ti.com> on 2003/11/12 10:26:43 UTC

PortletRequestDispatcher...

Hi,

how do I integrate a servlet within a portlet? For example, just a 
simple HelloWorld servlet which is executed within the portlet 
throughout the PortletRequestDispatcher...

Here is the "doView(...)" method of the portlet:
<CODE>
protected void doView(RenderRequest renderReq, RenderResponse renderRes) 
throws PortletException, IOException {
   renderRes.setContentType("text/html");

   String servletName = getPortletConfig().getInitParameter("servletName");
   PortletRequestDispatcher rd = 
getPortletContext().getRequestDispatcher(servletName);
   rd.include(renderReq, renderRes);
}
</CODE>

ServletTest/src/com/mycompany/portlet/ServletPortlet.java
--> this is the path to the portlet (ServletPortlet.java)

ServletTest/src/com/mycompany/servlet/HelloWorld.java
--> this is the path to the servlet (HelloWorld.java)

In "portlet.xml"

<init-param>
  <name>servletName</name>
  <value>???</value>
</init-param>

what "<value>" do I have to specify?

Best regards,

- Stephan Huber


Re: PortletRequestDispatcher...

Posted by "Glenn R. Golden" <gg...@umich.edu>.
I believe that getRequestDispatcher wants a string relative to the base 
of the context - so it's either a file or a servlet mapped partial URL. 
  See the portlet (or perhaps the servlet) spec.

On Wednesday, November 12, 2003, at 04:26  AM, Stephan Huber wrote:

> Hi,
>
> how do I integrate a servlet within a portlet? For example, just a 
> simple HelloWorld servlet which is executed within the portlet 
> throughout the PortletRequestDispatcher...
>
> Here is the "doView(...)" method of the portlet:
> <CODE>
> protected void doView(RenderRequest renderReq, RenderResponse 
> renderRes) throws PortletException, IOException {
>   renderRes.setContentType("text/html");
>
>   String servletName = 
> getPortletConfig().getInitParameter("servletName");
>   PortletRequestDispatcher rd = 
> getPortletContext().getRequestDispatcher(servletName);
>   rd.include(renderReq, renderRes);
> }
> </CODE>
>
> ServletTest/src/com/mycompany/portlet/ServletPortlet.java
> --> this is the path to the portlet (ServletPortlet.java)
>
> ServletTest/src/com/mycompany/servlet/HelloWorld.java
> --> this is the path to the servlet (HelloWorld.java)
>
> In "portlet.xml"
>
> <init-param>
>  <name>servletName</name>
>  <value>???</value>
> </init-param>
>
> what "<value>" do I have to specify?
>
> Best regards,
>
> - Stephan Huber