File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "word - txt upload help " Watch "word - txt upload help " New topic
Author

word - txt upload help

Preeti Sikri
Ranch Hand

Joined: Mar 01, 2001
Posts: 30
Hi
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
Hi,
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.
Arun
SCJP.


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 java@sunguru.com or let me know as to how i can convert a servlet in to a bean coz i have a fileupload servlet
Amit


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

Joined: Mar 15, 2001
Posts: 55
hi
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 15seconds.com.

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)
proceed=false;
if(proceed)
{
inputLine = new String (tmpbuffer, 0,length);
StringTokenizer tokenizer=new StringTokenizer(inputLine,";");
while(tokenizer.hasMoreTokens())
{
String subtoken=tokenizer.nextToken();
if(subtoken.startsWith("fil")) //If subtoken starts with file get the file name
{
filename=subtoken.substring(11,subtoken.length()-3);
can_write=true;

}
if(can_write)
{
if(!inputLine.startsWith("Content") && !inputLine.startsWith("----"))
{
tmpfile.write(tmpbuffer,0,length); //write to tmpfile stream
total_bytes+=length;
}

}
}


}

}
Hope find it helpful
Regds
Hemanth
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: word - txt upload help