Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Applet Servlet Connection & Communication

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to save some information from an applet to a mySQL database using a Servlet. I can access the Servlet fine from a JSP but I can't get an Applet to connect to the servlet at all.

The code is as follows, any suggestions would be gratefully received.

Thanks in advance.


 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I can't get an Applet to connect to the servlet at all


What does this mean - what happens when the code is run? Are there any exceptions?

Since you use getCodeBase, the servlet seems to be hosted on the same server as the applet (which is a precondition for this to work at all), but is the servlet really listening at the URL where the applet is hosted?
 
Liz Costelloe
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Thanks for your reply.


What does this mean - what happens when the code is run? Are there any exceptions?



The applet code executes in full without throwing any errors. On the servlet side nothing happens, the doPost method is not invoked (and no errors occur).


but is the servlet really listening at the URL where the applet is hosted?



Terribly sorry, but I'm not sure exactly what you mean by this, I'm new to applets and servlets.

Yes, the applet and servlet are both hosted on the same server.

The servlet has responded to requests from JSPs but I'm not sure if this answers your question.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "listening to the URL" I mean that a servlet is configured to respond to particular URLs (the "servlet-mapping" elements in the web.xml file). It would be a very unusual setup to map a servlet to a directory that contains files to be served. That seems to be what you are doing with the "getCodebase" call in the URL constructor.

Can you invoke the servlet manually through the browser?

Another things to check are the web server access logs, to make sure that the request reaches the server.
 
Liz Costelloe
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

I do think I have the servlet configured to respond to http://an.ip.address:8080/structures/Save. The web.xml file is included below and I am able to invoke the servlet manually through a web browser.

I have tried looking through the web server (JBoss) logs but I'm not sure where the access logs are stored in JBoss. If you happen to know this, I would be grateful if you could point me in the right direction - I will keep looking of course, but it would save me some time.

Many thanks.



[ May 15, 2006: Message edited by: Liz Costelloe ]
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your web app is named "structures". But in which directory is the applet - is it in the top-level directory? Only then would getCodeBase return the proper directory. It might be a good idea to print out the URL which the applet is trying to access; I'm not quite sure what the "spec" parameter does.

Can't help you with JBoss - I never used it.
 
Liz Costelloe
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ulf,

Quick line just to say thanks for all your help!! At long last I have this applet and servlet communicating. In the end I got out a TCP viewer and noticed that there were a lot of 'Java' connections stuck waiting for responses so I extended my code like so:



As a result communication was established There were a few errors along the way (Permissions and an EOF error) but now all is working smoothly.

Thanks again for all your help!!
[ May 24, 2006: Message edited by: Liz Costelloe ]
 
Our first order of business must be this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic