• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to upload an acrobat file from client to server

 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to writing web apps. This is an imaginary project and I am still in the design phase. I just needed some ideas to do this uploading.

I have an acrobat file on a client's system under c:/course. When the client logs in, he sees a link to upload a file and clicks it. An applet loads and shows a file dialog to choose the file. He selects the file. At this point I want the file to be saved in the servers' WEB-INF/course directory. How do I do this? I am using tomcat server.
 
Allen Bandela
Ranch Hand
Posts: 128
Eclipse IDE MS IE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to programming, but I just thought I could share my idea. You would use object serialization (objectoutputstream and objectinputstream) to get the pdf file onto the server. At the server you would place the file at the directory of your choice I guess. Hope this is of any help at all.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oooh, using a Java object serialisation? "That ain't gonna work!" You can only use object deserialisation when you have a file/stream formatted as a Java serialised object; and you can only serialise a Java object in memory into a stream. But a PDF file is neither of those - it isn't a Java serialised object, and it isn't a Java object in memory.

Instead you to upload the file using an HTML form; something like:You need to replace the ? with the path of the resource (typically a servlet) to which the HTTP POST request will be directed. You will then find the 'file' POST parameter in the body of the request, and this will contain the bytes representing the PDF. All you need to do then is copy it onto the server's storage.

But, I don't know if you upload into the WAR directly - I've never tried this, for the following good reason: if you ever have to modify the application and redeploy the WAR, you will lose all the contents of the previous one - so any uploads are gone forever. Similarly, some containers extract a WAR when it is deployed into a location on the server; this helps optimise request time invocations and JSP translations, since the WAR file doesn't have to be decompressed each time. But again, if you try to copy to the extracted location, that gets overwritten with any re-deployment of the application.

A much better solution is to copy to a permanent directory on the server - something still inaccessible to clients, but outside the J2EE container. For example, on a Unix box if your home directory is ~ (a Unix shortcut), then you would might want to copy the file into ~/courses/. The advantage now is that any redeployment of the application or restarts of the J2EE server don't touch the contents of the ~/courses/ directory - and since it's in your filespace, it's just as accessible to you as any other path, but impossible to access by any client.

Hope that helps.
[ March 18, 2006: Message edited by: Charles Lyons ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Servlets forum.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest to look in slide project. You can mount webdav server as a webfolder and drag&drop files there. Slider works with any j2ee container including tomcat
 
Pere Cortada
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the FileUpload project in apache.commons

http://jakarta.apache.org/commons/fileupload/

Be aware that the examples doesn't work in IE, if you 've to use this for the upload check the fileupload mailing list in

http://jakarta.apache.org/site/mail.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!