Forwarding the HttpServletRequest to another servlet

hi,

is there a way to forward the HttpServletRequest object (the parameter in doPost method) to another servlet in another machine

currently I have a servlet class in a machine. When the doPost() method of this class is invoked, I simply want the HttpServletRequest object to be redirected to another servlet object (which is located in a different machine, hence different IP)

I have tried creating an HttpClient object from the common.httpclient.jar, but the servlet just throws an exception. I'm assuming HttpClient cannot be used inside a class that extends HttpServlet.

[600 byte] By [xyperxexa] at [2007-11-27 3:47:14]
# 1

> an exception

Please be specific.

If you want to invoke another servlet in another machine, just invoke it by a simple request URL which fits in the url-pattern of the servlet-mapping of this servlet.

Send a redirect with query parameters to the desired URL or invoke a POST with the POST parameters to the desired URL.

BalusCa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

This is how my doPost() looks like...

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

PrintWriter writer = response.getWriter();

if (ServletFileUpload.isMultipartContent(request)) {

HttpClient client = new HttpClient();

}

else {

writer.println("HTML encoding type does not support file sending");

}

}

if i remove the line HttpClient client = new HttpClient(), there will be no exception

By the way, this is the exception as displayed in the browser...

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError

FmsDummyServlet.doPost(FmsDummyServlet.java:27)

javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:402)

org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)

javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

xyperxexa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
from where your give the HttpCilent class ? this is no found in servlet api or in j2ee i think thanks
javaskilleda at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpClient.htmlIt's one of the apache commons.Back to the problem: well, this one execption is self-explaining. Add it to the classpath.
BalusCa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
oh! HttpClient class is from the jakarta commons (httpclient.jar)
xyperxexa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
ok am serach for this class and i see is from apache but didi't understand for that any wayput the jar file for represent is HttpClient in lib folder in web-inf i think is the jar file not defined in ur applicationthanks
javaskilleda at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

> http://jakarta.apache.org/commons/httpclient/apidocs/o

> rg/apache/commons/httpclient/HttpClient.html

> It's one of the apache commons.

>

>

> Back to the problem: well, this one execption is

> self-explaining. Add it to the classpath.

which path should i add to the classpath? the path of the jar file or the servlet path?

xyperxexa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
You don't need to add more paths, just add the whole JAR to the current classpath of the running environment.
BalusCa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

> You don't need to add more paths, just add the whole

> JAR to the current classpath of the running

> environment.

i tried adding the path to environment variable "classpath". i've also added the jar file to the build path. but the same exception appears.

i really appreciate your help, thanks!

xyperxexa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

Likely you added it to the environment variable classpath of the operating system, not to the classpath of the running java environment (which is actually the application server).

The classpath differs per running java environment. This can be the default installed JRE in c:\java\bin or so, this can be the IDE (Eclipse: project settings, build path, don't forget to export), or this can be the Application Server (usually it's the /lib folder, you can find it specified in the server.xml).

BalusCa at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

hey

this instruction for soultion your problem

1-/WEB-INF/lib/the jars file needed

2- /META-INF/MANIFEST.MF ===> this depandencey of jar files

finally restart your web server

NOTE:

all jar files in lib folser will be settn in classpath automaticaly from

web server

tell what happen you after trace this

thanks

javaskilleda at 2007-7-12 8:51:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...