Problem invoking servlet from portlet with PortletRequestDispatcher.invoke

Hello,

I think this has been asked before, but I can't seem to find an answer to it. I am trying to invoke a Servlet from my FacesPortlet class, but I keep getting this error:

com.ibm.wps.servlet.response.ServletResponseWrapper sendError EJPPG1039E: HTTP error reported by Portlet: 404 SRVE0190E: File not found: "/TestServlet"

Here is the code I am using to call my servlet from the render() method of my portlet class:

PortletContext ctxt = (PortletContext)FacesContext.getCurrentInstance().getExternalContext().getConte xt();

PortletRequestDispatcher dispatcher = ctxt.getRequestDispatcher("/TestServlet");

dispatcher.include(request, response);

My servlet has a mapping in my web.xml file:

<servlet>

<display-name>TestServlet</display-name>

<servlet-name>TestServlet</servlet-name>

<servlet-class>pagecode.TestServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>TestServlet</servlet-name>

<url-pattern>/TestServlet</url-pattern>

</servlet-mapping>

I think my URL is messed up.... I have seen posts that recommend adding renderRequest.getContextPath() to the URL, but that didn't seem to work. If anyone can point me in the right direction I would be grateful.

Thanks in advance!

[1398 byte] By [lentaria] at [2007-11-26 18:58:30]
# 1
Ok, so I added /servlet to my path and things work great now. Portlet invokes my servlet in doViewportletrequestdispatcher = getPortletContext().getRequestDispatcher("/servlet/TestServlet");
lentaria at 2007-7-9 20:38:57 > top of Java-index,Web & Directory Servers,Portal Servers...
# 2
hi,Would you please share the code which is calling the servlet from ur Portlet?Actually i have to call a servlet when a user clicks on the portal href. can u pls guide me..
hariJavaa at 2007-7-9 20:38:58 > top of Java-index,Web & Directory Servers,Portal Servers...
# 3

hari,

I don't have the solution right in front of me, but it goes something like this:

PortletRequestDispatcher portletrequestdispatcher = getPortletContext().getRequestDispatcher(yourservleturl);

portletrequestdispatcher.include(request, response);

This will invoke the doGet method of your servlet. If you are invoking your servlet via html href you can also just provide the servlet url as the href parameter. To do that you would have to do something like:

<a href ="<%= renderResponse.encodeURL(renderRequest.getContextPath()+

"/servlet/yourservletname") %>"/>

This may not be the solution you were looking for, but this is how I invoked my servlet from my portlet. Best of luck.

lentaria at 2007-7-9 20:38:58 > top of Java-index,Web & Directory Servers,Portal Servers...