• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending A File From An Applet To A Servlet

ch praveen
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)) ) {
catch(final MalformedURLException e) {
System.out.println("Caught Malformed URL Exception");
catch(final IOException e) {
System.out.println("Caught IO Exception");
finally {
try {
catch(Exception e) { }
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic