Hi, I am supposed to send a String data from a JSP in one application to a servlet in another application (they reside on different servers). Now in the JSP,I have used the URL of the servlet to open a HttpURLConnection and I am writing the String into a DataOutputStream. I have done a setRequestMethod("POST") to post my data to the servlet. But I'm unable to read any data from the request object in the servlet. Please help me,thanks in advance, Regards, pramod.
When is the data set? The JSP is executed when the user makes a request for the JSP's URL. If the user is supposed to fill in a form and submit the data, it isn't there to be sent. In this case your servlet which processes the POST of the form should forward the data to the second app. Perhaps you need to give us a little more detail as to the sequence of events in your problem. In any case, this is not an IO question. I'm going to move this topic to the Servlets forum. Maybe those knowledgable folks will see something I missed.
Hi, Thanks a lot for the replies. I actually worked it out last night and I managed to get over the problem. But I'll tell you what the problem was and how I went about it. And if there is a better way, maybe I can know about it too. Say I have two applications, App1 and App2, residing on 2 different servers. Now App1 needs to perform certain operations which are actually done in App2. So a JSP in App1 has to send a request in a known format (actually an XML, but it is converted to a String object by App1 before it starts communicating with App2).This request will be read by a servlet in App2. Depending on this request, it has to send a response back (which will be again an XML converted to a String object). So what I have done is, in App1,using the URL of the App2 servlet (which has to handle the request) I have opened a URLConnection like this:
url = new URL("http://localhost:8100/uc20/servlet/SchedulerServlet"); uc = (HttpURLConnection)url.openConnection(); uc.setDoOutput(true); uc.setDoInput(true); uc.setUseCaches(false); uc.setRequestMethod("POST"); uc.setRequestProperty("Content-type", "html/text-plain"); uc.connect(); and I wrote the String to an OutPutStream using DataOutputStream and closed it.
On the other side the servlet in App2 looks like this: - (here I'm simply sending the same request back for testing purposes)