• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

applet-servlet communication.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

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:

Applet 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A quick glance at the Java Documentation for URLConnection confirms my suspicions:


# 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.
 
Gauri Deshmukh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Joe,

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.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gauri Deshmukh:

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic