• 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

Upload File Servlet Example

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friend
Could anyone please show me an example of an Upload File Servlet?
Thanks a lot
 
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the 'oreilly' package can be found here: www.servlets.com/cos
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic