• 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

word - txt upload help

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic