aspose file tools*
The moose likes Servlets and the fly likes Upload File Servlet Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Upload File Servlet Example" Watch "Upload File Servlet Example" New topic
Author

Upload File Servlet Example

lu v thuan
Ranch Hand

Joined: Oct 25, 2001
Posts: 32
Hi Friend
Could anyone please show me an example of an Upload File Servlet?
Thanks a lot
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
better use oreilly package...they hv included the example..
works fine with me
good luck
malhar
Originally posted by lu v thuan:
Hi Friend
Could anyone please show me an example of an Upload File Servlet?
Thanks a lot


Malhar Barai
SOA & Java Book
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

the 'oreilly' package can be found here: www.servlets.com/cos
Brian E
Greenhorn

Joined: Sep 07, 2001
Posts: 12
I've been successful in implementing the oreilly package (what a lifesaver), specifically the MultipartRequest class. My next step is to be able to insert what is uploaded into a database using, presumably, MultipartParser from the same package.
I am running Tomcat standalone and Oracle 8.1.7. The file to be uploaded will be a delimitted text file. My ultimate goal is to be able to parse through the contents of the loaded file and load that information to a new table in the database for later viewing. Can some of you Ranch Hands point me in the right direction? Would it be better to upload the file to the server and then transfer it to the DB from there? Or should I go with the MultipartParser? I've read through Jason's documentation and am a bit stuck. Any help would be appreciated.
Thanks.
Brian
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
I'd say your intuition is right. Upload the file first and then parse it.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Brian E
Greenhorn

Joined: Sep 07, 2001
Posts: 12
Kyle.
Thanks for the reply. Your experience is obviously much greater than mine. I am, in fact, relatively new to this all. Could you perhaps point me in the right direction or give me some ideas on how you would choose to proceed in this situation?
Thanks in advance for your help.
Brian
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Hopefully Kyle won't mind if I butt in.

I'm back from a night at 'the bar' (ugh), and I need something to do.

My own thoughts run like this:

1. Use the MultipartRequest object, and have those files nicely uploaded to the 'upload' directory.

2. Use java.io classes to open that file.
from the api: BufferedReader in = new BufferedReader(new FileReader("foo.in"));

I think the MultipartRequest can return you the file object itself? Failing that, I *know* you can get the filename, so you'd substitute that method call for the "foo.in" parameter.

3. Read it line by line ( String ln = in.readLine(); )

4. Parse the just-read line using a StringTokenizer (because it will be nicely tab/comma/colon delimited. The point is.. it's delimited) StringTokenizer st = new StringTokenizer(ln, "/t");

5. Use the funky new JDBC 2.0 BatchUpdate feature. Hopefully Oracle has a driver by now? It should all look something like:



Does that cover it? It's 3am.. I can't be sure.

[This message has been edited by Mike Curwen (edited November 03, 2001).]
Stephen Wei
Ranch Hand

Joined: Oct 09, 2001
Posts: 73
Hello, the above comments are very helpful. But for my case, I am uploading an EXCEL file to the server. Can the approach be the same?
So do I upload the excel file to the server first, then parse it?
But excel file is different from CSV file, how do I parse excel file?
Thanks!
------------------
Sun Certified Programmer for Java Platform


Sun Certified Programmer for Java Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload File Servlet Example