On Fri, 10 Jan 2003, Tref Gare wrote:
> Date: Fri, 10 Jan 2003 14:20:29 +1100 > From: Tref Gare <[EMAIL PROTECTED]> > Reply-To: Tomcat Users List <[EMAIL PROTECTED]> > To: Tomcat Users List <[EMAIL PROTECTED]> > Subject: request forwarding with TC4.1.12 > > Hi all, > > Does anyone know if it's possible with Tomcat to forward a request from > a Servlet to a url on a remote server. > > More specifically I need to process an upload form on one server (using > Tomcat) and then pass the request along with the uploaded file to > another server (using PHP). The details of why we need to do this > rather than handling the upload and processing all on the same server > are tedious and to say the least frustrating. Take my word for it, we > need to. > > Now as far as I know request forwarding is only feasible within the same > server that the original request is received on. However I've come > across postings suggesting that Jetty can forward a request to a remote > server. Does anyone have any idea of whether Tomcat may be able to > handle this in any way? > If by "forward" you mean "RequestDispatcher.forward()", then you cannot do this -- that only works for forwarding a request to another servlet in the same webapp. There's two fairly easy ways to do what you're after, however: * After you've processed the uploaded form locally, issue a *redirect* to the absolute URL of your PHP application. However, this is likely to cause problems for your users if the transaction was a POST, because the browser is likely to ask "should I submit this form again to some other site" depending on the user's security settings. The other thing to note is that it's the PHP app that will, in this case, create the response page that the user sees. * Inside your servlet, after you've processed the form yourself, use the java.net.HttpURLConnection class (or something like it) to establish an HTTP connection from your application (as an HTTP client) to the PHP app as a server. You'll need to understand enough about HTTP to make your transaction look like one that came directly from a browser, but it is not that hard. This approach also leaves your servlet in control of the response that ultimately gets sent back to the user. > Thanks for any help, > > Tref > Craig -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
