• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

file upload..urgent..

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,
can anyone please tell me how to upload a file from hard disc to a server in java.a piece of sample code would be of great help.
regards
karan
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,
i found the following piece of code but it gives me errors in the first two import statements and the getOutputStream statemets,it says "cannot resolve symbol",does it mean that i got to have some netscape class files in order to run it?please help me out..its urgent..i would really appreciate it.
import netscape.server.applet.HttpApplet;
import netscape.server.applet.ServerApplet;
import java.io.*;
import java.lang.*;
import java.net.Socket;
import java.net.InetAddress;
import java.util.Hashtable;
import java.util.Enumeration;
class UploadApplet extends HttpApplet {
public void run() throws Exception {
int cclen, bytesread = 0;
int totbytes = 0;
int bytesremain = 0;
int bytesavail = 0;
String line;
byte b[] = new byte[9192];
line = getHeader("content-length");
cclen = Integer.parseInt(line);
PrintStream out = getOutputStream();
InputStream is = getInputStream();
DataInputStream di = new DataInputStream(is);
if (returnNormalResponse("text/plain")) {
out.print(header);
out.println(cclen);
out.flush();
FileOutputStream fos = new FileOutputStream("/tmp/testfile");
while (totbytes < cclen)
{
bytesread = di.read(b, 0, 8192);
//out.println(bytesread);
//out.flush();
if (bytesread == -1)
break;
fos.write(b, 0, bytesread);
totbytes += bytesread;
}
fos.close();
out.print(trailer);
out.flush();
}
}
private static final String header = "<h1>Write in Progress</h1>\n<ul>\n";
private static final String trailer = "Finished</ul>\n";
}
regards
karan
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karan,
how r u
of course you need some classes. I don't know them exactly but I have used netscape.security classes. I think these are similar. I needed to download those extra classes from the sun site, so I advise you to search there unless some one suggest you more helpful idea.
Regards,
MAC.
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jimi,
hows it going..thanks for the advice..i will search for the class files now,but just out of curiosity,do u know of any better way to upload files in java?i would appreciate any help in this regard.
regards
karan
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi karan
there is an article at www.onjava.com by Budi Kurniwan which gives details about uploading files
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
somebody please tell me if file uploading is possible with java script,if yes then how can i integrate java script with java?
regards
karan
PS-i know its possible with CGI but i dunno how to integrate CGI with java
 
Jimi Rock
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karan, I have another suggestion as I have gone through the file uploading process step by step successfully.
I have used a signed applet on the client end and a servlet on the server side.
I can provide you with all necessary steps. I have tried to mail you but your email is unavailable.
I think that keep mailing is good in this case. just email me or provide your email in your javaranch profile if my suggestion is appropriate with your case.
Regards,
MAC.
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jimi,
i have mailed you on the email acct given in your javaranch profile.please read it and reply me back..
regards
karan
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Karan...
I have a problem similar to yours .need to upload PDF file from client ot server .....Did your code for uploading work..If it has please forward me your code on anuj.anand@cna.com
Your response would be appreciated.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are not only thinking about upload from applet to servlet but also from html (javascript) to servlet, the easiest way will be using com.oreilly.servlet.
Hope it helps
Detlev
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the URL detlev,actually i stumbled across that site before,and i downloaded the zip file from there,but it sounded too complex to make any sense to me,if you could make any sense out of it then plz tell me too..i would really appreciate that.
regards
karan
 
Detlev Beutner
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at this:

The second line handles the upload! Could it be easier? I do not think so. Browse through the API-docs; they are ok.
Hope it helps
Detlev
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
There is a package available for uploading files and images etc for free at http://www.jspsmart.com/ It is ofcourse to upload files from html using JSP. Hope this serves your purpose.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there
can anyone put some light on the methods available for uploading a file from Applet without signing it... (I don't think there are, but i have found a work around for IE which doesn't work in Netscape 6.x )
If there is any such method, it'll be of great help to me..
Links would also do better.
regards
raghav..
 
Jimi Rock
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Raghav, Applet cannot access local system resources without being signed. Unfortuantly,Signing mechanisms differ from one browser to another.
I have gone throgh signing applet with a lot of pain because lack of documentation over the web. at last, I have found that the best way is to sign for java plugin so that ur applet can run independent of the client browser.
Anuj, the file uploading application that we have and Karan is trying to use is able to upload a file of any type. I hope that ur problem is solved, just tell if any problem occured, we all will try hard to help...
Regards,
MAC.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created an applet that allows users multiple file uploads. It is very simple and easy to understand and can change the layout and destinations through parameters in the HTML page.
I have it signed by a certificate from Thawte and this multi-purpose cert. can be used for Netscape and IE. The .cab and .jar file just have to include the appropriate security classes form each browser.
Need anwsers or help, email me at jbrett@roadrunner.nf.net
------------------
Jonathan Brett, SCJP
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic