File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Urgent :  Servlet to Servlet(in another server) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Urgent :  Servlet to Servlet(in another server)" Watch "Urgent :  Servlet to Servlet(in another server)" New topic
Author

Urgent : Servlet to Servlet(in another server)

James Sivakumar
Greenhorn

Joined: Nov 16, 2000
Posts: 21
I have a servlet in my server. And I have another servlet in another server, in some other place. I need to communicate with that remote server, like passing values and retrieving values.
I used RequestDispatcher, but it isn't working fine.
this is the code of my login screen and two servlets.
login.html:
<html>
<body>
<form name="login" method="get" action="http://dev4:8080/examples/servlet/checklogin1">
Username <input type="text" name="username">
Password <input type="password" name="password">
<input type="submit" value="submit">
</form>
</body>
</html>
checklogin1(my servlet in my server):
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class checklogin1 extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
req.getParameter("username");
req.getParameter("password");
RequestDispatcher sc1 =
getServletContext().getRequestDispatcher("/http://dev1:8080/examples/servlet/checklogin2");
sc1.forward(req, res);

}
}

checklogin2(servlet in the remote server):
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;

public class checklogin2 extends HttpServlet
{
public void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println(req.getParameter("username"));
out.println(req.getParameter("password"));
RequestDispatcher sc2 =getServletContext().getRequestDispatcher("/http://dev4:8080/examples/servlet/checklogin1");
out.println(sc2);
.
.
.
.
}
}

please reply back as soon as possible!
thanx folks!

Marya Doery
Greenhorn

Joined: Dec 27, 2000
Posts: 15
If you read the javadocs for RequestDispatcher, you'll find this for getRequestDispatcher(String path) method:
"The pathname must begin with a "/" and is interpreted as relative to the current context root."
Since the context is defined for a web application _in_ your servlet container, I don't think you can use RequestDispatcher to go outside the container.
Look into java.net.URL or java.net.URLConnection instead. Maybe that would work.
Also it looks like you're trying to post form variables by printing them to the response's output stream. That doesn't seem likely to work, even if you were submitting them to a local url. Something like this would normally print your variables to the browser. Also - you cannot print the RequestDispatcher to the response's output stream; it'll just output the results of the dispatcher's toString() method to your browser. Take a look at a book or online tutorial on servlets to find out more about what the PrintWriter of the response object does.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Urgent : Servlet to Servlet(in another server)
 
Similar Threads
getting HTTP Status 404 - /servlet/Firstservlet error in Tomcat
Requested Dispatcher
problem with setContentType() method
Help me please
More simple doubts....errr