• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

File Upload

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I want my webserver to have "file upload" capabilities. Can I use Tomcat webserver in this case? Also, i don't know how to retrieve the attached file/s from client to the server (servlet). can anyone help me on this? pls provide code snippets if possible. thanks.
Jonathan
 
Tano Ortiga
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Additional Questions:
how do i "store" the file into an object/variable?
how do i "store" the file into a database ?
thanks again.
Jonathan
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jonathan,
here's code for file upload.
HTML:
<form ENCTYPE="multipart/form-data" action="/servlet/FileUpLoad" method="POST">
<input name='upfile' type='file'>
<input type="submit" name="Upload" value="Transfer the file">
</form>
JavaCode:
int iTotalBytes = this.oRequest.getContentLength();
BufferedReader oInFileData= new BufferedReader(
new InputStreamReader(this.oRequest.getInputStream()));
char[] arData = new char[iTotalBytes];
oInFileData.read(arData);
arData contains the contents of the file as well as some more information regarding
the request. you can filter out what you need from the array.
Hope this helps
Satish
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also obtain the O'reilly multi-part request handler (which parses an enctype of multipart that file-uploading requires). You can find the library at www.servlets.com.
 
Tano Ortiga
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now,there is a html file in client.
But i ave a question,
if they are both java source code in client/Server.
How to code in client??
 
I can't take it! You are too smart for me! Here is the tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic