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 Communication

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm writing my first program for performing applet-servlet communication, and no matter what I try, I have not been able to run it. I know my servlet is fine, 'coz i can get the results if i give it's url directly in the browser. I'm trying to implement an (only) applet-servlet example in the book: Professional Java Server programming, chapter 11. I've even used some sort of applet coverter plug-in, which the book suggests to use in case of error.
The error i'm getting is : java.io.FileNotFoundException, and then it says, it can't find the servlet, although the servlet IS initialized !!. I think it has something to do with the security.
I'm using DataOutputStream to send an SQL query to the servlet, and then using InputStreamReader to read the results, which servlets writer onto the PrintWriter obtained from the request object.
Can somebody help me?
Thanks a lot in advance,
Aman
 
Trailboss
Posts: 23209
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check www.javaranch.com/common.html and look for ObjectServlet.java and HTTP.java
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
I tried to use the class com.javaranch.common.Http for a similar problem (Applet to Servlet communication). I can read from the servlet. However when I try to write to it, I also get "FileNotFoundException" excpetion. My Applet code to send an object to the servlet is as follow:
URL myurl = new URL(getCodeBase(), "/servlet/SimpleServlet");
URLConnection con = myurl.openConnection();
con.setUseCaches( false );
con.setDoOutput(true);
con.setRequestProperty("Content-type","application/octet-stream");
Object obj = new String(fname);
ObjectOutputStream out = new ObjectOutputStream( new GZIPOutputStream( con.getOutputStream() ) );
if ( obj != null )
{
out.writeObject( obj );
}
out.close();
Any help or idea is appreciated.
Regards,
Arsalan Madjd

 
Saloon Keeper
Posts: 22248
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What line in your sample code throws the exception?
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic