Hi, as you will see I am quite new to servlets, so sorry if the question is not smart I have this servlet A that handles requests from my clients. These clients ask some data, and A finds out to which other servlet B or C it must request that data. How can I call servlet B from A, asking it to send back the needed data ? Thanks, Stephane
B need not be a servlet, it can be an ordinary java component. You can instanciate it like a normal java class, and invoke methods on it to get back the data you want. You can also pass the request and response object to it, and it can pass back the data in the request, or it can write it directly to the output stream which it obtains from response.
Joined: Mar 07, 2002
My problem is I have to use a Servlet, but don't see how to forward request and response to it. The forward method from RequestDispatcher only applies to resources on the same server (not the case here) and sendRedirect seem not to pass the data, as I get a null pointer if I try request.getContentType() in Servlet B, after having set response.setContentType to some value in Servlet A. I presume this is some kind of session problem. Can anybody help me ? Thanks In fact, I have in servlet A : response.setContentType( "text/xml" ); PrintWriter out = response.getWriter(); out.write("<test></test>"); response.sendRedirect("http://localhost:8080/myApplication/servlet/LocalDemonstratorServlet"); And in servlet B : String ct = this.request.getContentType(); System.out.println("ct : "+ct); Which prints null [ July 02, 2002: Message edited by: Stephane Weber ]
Joined: Aug 23, 2001
Open a URL connection to the other servlet, get the data as XML .. say , parse it and do your processing....