File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes word - txt upload help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "word - txt upload help " Watch "word - txt upload help " New topic

word - txt upload help

Preeti Sikri
Ranch Hand

Joined: Mar 01, 2001
Posts: 30
I am creating a site using JSP in which I want a functionality where a person can
1) upload his resume (in doc format)
2) then I can convert the doc file to a txt file and can save the resume in the database
How can I achive this
any help would be great Regards Preeti
Arunagiri, Shanmugham
Ranch Hand

Joined: Jan 23, 2001
Posts: 46
You can upload a word file by using a multipart/form-data type in the form action tag. Later u have to read the header and separate the data part from it. This can be written to the local hard disk on the server side. By this way u can download the word document. I have done the same thing in my project.
I think a sample code on the same is also given in Jasen Hunters Java Servlet Book.

Sun Certified Programmer for Java2 Platform
Amit Roy
Ranch Hand

Joined: Oct 10, 2000
Posts: 132
Hi preeti and Arunagiri
I dont have a answer to ur question but a question as u both have done a upload function in ur sites in JSP u mite have used a bean i wanted to know as to how do u put the uploaded file in the desired directory if u all dont mind can you send me the bean at or let me know as to how i can convert a servlet in to a bean coz i have a fileupload servlet

<I>Chance Favours the Prepared minds"</I>
hemanth kumar
Ranch Hand

Joined: Mar 15, 2001
Posts: 55
As Arun said u have to use Enctype=Multipart/form in the tag form.
Heres a sample of the FORM tag
<form id="frmUpload" name="frmUpload" METHOD="post" ENCTYPE="multipart/form-data">
Use the <FILE> tag for getting the file to be uploaded
The theory is that when u post the form the file to be uploaded goes as header data and u have to manually pluck out the file data from the header from the page to which u have posted it to.
There is a very nice explanation to all this in

the code below should do the job

ServletInputStream ip=request.getInputStream();
byte[] tmpbuffer = new byte[8192];
int length=0;
String inputLine=null;
boolean proceed =true;
length = ip.readLine( tmpbuffer, 0, tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, length);
String filename=null;
boolean can_write=false;
FileOutputStream tmpfile=new FileOutputStream("tmpf.txt"); //create a tmpf.txt file on the server
int total_bytes=0,bytes_read=0,k=0;
boolean error=false;

while (proceed)
length = ip.readLine( tmpbuffer, 0, tmpbuffer.length);
if(length < 0)
inputLine = new String (tmpbuffer, 0,length);
StringTokenizer tokenizer=new StringTokenizer(inputLine,";");
String subtoken=tokenizer.nextToken();
if(subtoken.startsWith("fil")) //If subtoken starts with file get the file name

if(!inputLine.startsWith("Content") && !inputLine.startsWith("----"))
tmpfile.write(tmpbuffer,0,length); //write to tmpfile stream



Hope find it helpful
I agree. Here's the link:
subject: word - txt upload help
It's not a secret anymore!