This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Applets and the fly likes Sending A File From An Applet To A Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Sending A File From An Applet To A Servlet" Watch "Sending A File From An Applet To A Servlet" New topic
Author

Sending A File From An Applet To A Servlet

ch praveen
Ranch Hand

Joined: Mar 08, 2004
Posts: 67
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending A File From An Applet To A Servlet
 
Similar Threads
error outputting a pdf file
Generating PDF and displaying it ...
How to Return a File using Servlet
Servlet Not Responding
PDF File Streaming in a JSP