Word deocument MS SQL SERVER 2000 and JSP

Hello,

I am have seen some application that does the following and I wonder if this is possible. I have a series of word documents/templates that will be used for coresspondance purpose. The thing is some of the fields in the template will be filled from the database(MS SQL SERVER 2000). Just like mail merge. What my question is will jsp populate the word document by fetching the required data from the DB ?

Thank you in advance for your reponses,
Lalibela
:14:15
LalibelaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
Servlets can do this, the summary steps are:

1- read the word doument from database as byte[]
2- set content type as following      
response.setContentType("application/msword:);

3- stream the content out:

byte[] wordContent = getTheWordcontentFromDataBase();

      ServletOutputStream outStream;
      outStream = response.getOutputStream();
      outStream.write(wordContent);

0
TimYatesCommented:
You are probably best reading the document in in blocks and writing these blocks out to the browser, rather than reading the whole thing into e byte buffer (as it may be larger than the size of an int)

BufferedInputStream bis = null ;
BufferedOutputStream bos = null ;
try
{
    bis = new BufferedInputStream( new FileInputStream( filename ) ) ;
    byte[] bfr = new byte[ 4000 ] ;
    response.setContentType( "application/msword" );
    response.setHeader( "Content-Disposition", "attachment; filename=" + filename ) ;
    bos = new BufferedOutputStream( response.getOutputStream() ) ;
    int cnt = 0 ;
    while( ( cnt = bis.read( bfr, 0, bfr.length ) ) > 0 )
    {
        bos.write( bfr, 0, cnt ) ;
    }
}
catch( IOException ex )
{
    ex.printStackTrace() ;
}
finally
{
    try { if( bis != null ) bis.close() ; } catch( IOException ex ) {}
}
0
TimYatesCommented:
Also, this may help:

http://www.lowagie.com/iText/

it is a library allowing you to create PDFs on the fly...

To create DOC files this may help:

http://radio.javaranch.com/channel/val/2004/10/16/1097909528000.html
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

LalibelaAuthor Commented:
Hello,

Thank you for your responses. But my problem is not reading a word document stored in DB. I have the word document in web root application. What I want is to fill the template fields wtih data feteched from the DB. Just like mail merge in word.

Thanks,
:14:15
0
LalibelaAuthor Commented:
Hello,

Here is a solution I found... Jakarta velocity. If there is anybody in need of the same problem of mine you can use jakarta velocity and populate the database fields to hash map. If you need a unicode just set the content typt to utf-8.


Lalibela
:14:15
0
PAQ_ManCommented:
PAQed with points refunded (500)

PAQ_Man
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.