- Posted by: Girish K
- Posted on: July 19 2000 05:40 EDT
I have two servlets (S1 and S2) running on different machines (H1 and H2) respectively.
S1 receives a request from a client (say an applet). Initially, S1 performs validation on this request.
Then it sends this request to the servlet S2 on host H2.
I have used the RequestDispatcher Interface but it doesn't work. The forward(req, res) hangs !!
Any other options ? Also, what is the correct/best possible
way of sending a request from S1 to S2 ?
Thanks in advance,
forward and include works only for URL located on the same machine.
The redirect should works, else, you can use the class URL:
url = new URL(http://www.java.com");
conn = (HttpURLConnection)url.openConnection();
// Only if basic authentication is required
String auth = "Basic " +new sun.misc.BASE64Encoder().encode((user + ":" + password).getBytes());
conn.setRequestProperty("Authorization", " " + auth);
Should (may ?) works.
I meanwhile ventured the option that you have mentioned, but so far I have not had success on that.
to the second servlet, I have to set the attributes and headers of the first servlet.
Somehow, that part seems to not function.
Any leads on that would be helpful.
If you are running servlets on two machines, then you have to have some web server installed on them. Also, I am assuming that both the systems have the web server listening on a port such as port 80.
In this scenario, your servlets can be accessed using a URL which points to the servlet class folder.
Use response.sendReDirect(url name).