This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Applet - Servlet Communication  RSS feed

 
Amandeep Waraich
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
 
paul wheaton
Trailboss
Posts: 22526
Firefox Browser IntelliJ IDE 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
 
Arsalan Madjd
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

 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What line in your sample code throws the exception?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!