File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Upload File Servlet Example

 
lu v thuan
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friend
Could anyone please show me an example of an Upload File Servlet?
Thanks a lot
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the 'oreilly' package can be found here: www.servlets.com/cos
 
Brian E
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian E
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic