• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Sending A File From An Applet To A Servlet

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I want to send a file to servlet from an applet which will be sent to another client. [ Sending a file from one user to other through a servlet in my chatprogram ]. Iam getting a security exception and being restricted from accessing a file through an applet. As Iam implementing an encryption mechanism , I must load a file, encrypt it and must send it to servlet, which will be sent to other user.
The below is the code for an applet(encryption not included now).Plz give me your valuable suggestions.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class DispatchFile extends Applet {
public void init() {
String servletURL = "http://localhost:8080/examples/servlet/DispatchFileServlet";
URL url;
URLConnection con;
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
url = new URL(servletURL);
con = url.openConnection();
bos = new BufferedOutputStream(con.getOutputStream());
bis = new BufferedInputStream(new FileInputStream("give.txt"));
byte[] buff = new byte[2048];
int bytesread;
while(-1 != (bytesread=bis.read(buff,0,buff.length)) ) {
bos.write(buff,0,bytesread);
}
}
catch(final MalformedURLException e) {
System.out.println("Caught Malformed URL Exception");
}
catch(final IOException e) {
System.out.println("Caught IO Exception");
}
finally {
try {
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
}
catch(Exception e) { }
}
}
}
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic