I am trying to send some data ( a string) from an applet to a servlet. I can see that the data is getting sent to the servlet ( by using print stmts) but the servlet doesn't seem to get the data. I cannot see any prin stmts I have put in the servlet in my logs. Here is my code:
Here is what I am doing in my servlet:
It may be worth mentioning here that my applet has another URL connection opened to another servlet ( the applet gets some data from this servlet and sends some modified data to another servlet) . The first servlet connection works fine but the second one doesn't seem to get started from the applet.
CAn somebody tell me what I can do to fix this? Thanks, G.
I think we can rule out a bad URL and bad servlet mapping since you are not getting an exception on the client. Since you aren't getting ANY output on the servlet, I'm suspicious that you may be sending a GET rather than a POST (though I think the line servletConnection2.setDoInput(true); sets the request to be POST). Throw a simple doGet in your servlet for a test. What I'd bet is the problem is that you don't actually do a request on the URL. Your applet writes to it, but it doesn't read from it. HTTP is a request-response protocol. If you don't follow the protocol, I'd not be surprised when it doesn't work.
# The connection object is created by invoking the openConnection method on a URL. # The setup parameters and general request properties are manipulated. # The actual connection to the remote object is made, using the connect method. # The remote object becomes available. The header fields and the contents of the remote object can be accessed.
You are not actually making the request.
Joined: Dec 25, 2004
After this post yesterday I started getting an error : java.lang.IllegalException:Already Connected. I don't understand what tihs means or what could be causing this and why it wasn't there earlier. Also could you pls explain what you mean by : "You are not actually making the request" Sorry I am new to Java ...this may be trivial....but right now it has me stumped. THanks, G.
Also could you pls explain what you mean by : "You are not actually making the request"
You are constructing an HTTP POST request but you are not actually sending the request across the network. The actual request is made when either you invoke connect() explicity or you invoke a method which depends on the connection (i.e. getInputStream()) which will call connect() if not already invoked. As for your exception, you obviously made code changes but did not update us so we can only guess. I'd say you are invoking a method which must be called before the connection is made (i.e. setRequestProperty()) after the connection is made. Remember, you are working with a network protocol. There's a specific order in which things must occur. See the link I gave you to the documentation for more on what can be called when.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com