Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Probelm in applet/servlet communication

 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the servlet receive the value properly? Are you getting any exception at the servlet end?
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you try printing value?
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do some log trace at the applet end to make sure its making the connection.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i call directly the servlet is working fine. Problem is only when i call the servlet from the Applet.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it's an applet problem. Moving to our Applets forum.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i'm using only JApplet.
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apple/JApplet won't make any difference from connectivity point of view. In either case you will java.net.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic