Sushil Singh wrote:
>
> Hi,
> I am unable to compile my servlet which is using
> ServletRequest.getRequestDispatcher(), its giving error that no such
> method. I am having JVM 1.1.7
> If I use ServletContext.getRequestDispatcher(), its compiling and
> executing but I can not use this methid as I have to specify the full
> url in forward() method as my servlet is on some other server. And the
> specification shows that ServletContext.getRequestDispatcher() takes
> only absolute path (i.e. the url must start with /).
>
> RequestDispatcher rd = null;
> rd = req.getRequestDispatcher("http://hostname/servlet/Testservlet");
> rd.forward(req, res);
>
> Also if anybody can tell whether its possible to forward a request to a
> servlet/jsp which is residing on some other server (i.e. different
> domain). This is the reason why I have to specify the full url.

You can only forward within the same server. If look at the description
of ServletRequest.getRequestDispatcher(), you should see that it takes
a relative path, not an absolute URL.

To invoke a servlet on a different server, you need to redirect instead
of forward. In other words, get the browser to send a new request to
the other server instead of making a local call on the same server.

  res.sendRedirect("http://hostname/servlet/Testservlet");

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to