aspose file tools*
The moose likes Applets and the fly likes Probelm in applet/servlet communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Probelm in applet/servlet communication" Watch "Probelm in applet/servlet communication" New topic
Author

Probelm in applet/servlet communication

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
I tried to send a value to servlet, in the servlet the request parameter will be the value from the servlet and insert that value in a table.
But data is not getting inserted into table,if i call the servlet from my applet.I don't know where i'm going wrong.

My applet code:


My Servlet code:
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

Does the servlet receive the value properly? Are you getting any exception at the servlet end?


Swastik
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
No its not throwing any error. Even i hardcoded the value in the servlet. I'm facing the problem only when calling the servlet from the applet
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9


Did you try printing value?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
if i call the servlet from my applet its not printing any value..even null.The way i calling the servlet is correct?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

Do some log trace at the applet end to make sure its making the connection.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

What happens if you call that servlet directly from a browser? Does it work then?

Also, I would seriously suggest you redesign your servlet. It has instance fields that are set by requests. This makes it highly thread unsafe. Two concurrent requests (which is very common!) will cause problems. If "value" is your only instance field have doGetOrdoPost return the value instead of storing it in an instance field:

I should move this thread, but I'm not sure yet if it's an applet problem or a servlet problem. Hence my first question.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
If i call directly the servlet is working fine. Problem is only when i call the servlet from the Applet.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

So it's an applet problem. Moving to our Applets forum.
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
But i'm using only JApplet.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

Apple/JApplet won't make any difference from connectivity point of view. In either case you will java.net.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

It appears that in the applet you use the POST method to send the request. But you don't send any parameters; appending parameters to the URL is what you do if you're using the GET method. You could have done some debugging in the servlet to see if the parameter was being passed; I think it isn't.

You should decide in your servlet if you want to use POST or GET, and just handle one of them. Then you should write your applet to use whichever method you designed your servlet to use.

And in the applet you should URL-encode the parameter in case it includes characters other than letters and digits. (And why do you append an empty string to the URL? That does nothing but add confusion for the reader.)

Plenty of bad practices in the servlet too. I would at least commit the transaction and close the connection, but that's just the start.
 
 
subject: Probelm in applet/servlet communication