• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Probelm in applet/servlet communication

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Did you try printing value?
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do some log trace at the applet end to make sure its making the connection.
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But i'm using only JApplet.
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apple/JApplet won't make any difference from connectivity point of view. In either case you will java.net.
 
Sheriff
Posts: 28360
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic