permaculture playing cards*
The moose likes JSP and the fly likes Reading word document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Reading word document" Watch "Reading word document" New topic
Author

Reading word document

Aruna Velpuri
Greenhorn

Joined: May 07, 2003
Posts: 8
Hi
How can we read the word document content using JSP.
My requirement is "i have a word doc. When user wants i have to show the content of word doc in word".
Thanks in advance
Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189
Pardon me, but, "Huh?"
If you have a Word document on your server, and the user wants to view it in its native format, doesn't that imply that the user will have word.exe to open it?
If this is not the case, then I don't think you want to have the document on your server in Word format. Perhaps converting it the a PDF is better for you. Then of course, there is always Microsoft's messy, "save as a web page" option in word. I really cannot recommend the latter option -- PDF's are far superior.


Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Aruna Velpuri
Greenhorn

Joined: May 07, 2003
Posts: 8
Hi
Thanks for u r suggestion.
My requirement is first i will show list of documents(word, html) with link to print respective doucment.
When user clicks print then i have to show the content in new window then he will choose to print button to print.
Thanks in advance.
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Poor Aruna,
i would hate your "why easy, if it can be done complicated"-job, as word.exe can be perfectly started from a hyperlink and has a beautiful Print-Button.
if it doesn't kill you, it makes you hard
cb
narasimharao konjeti
Ranch Hand

Joined: Apr 26, 2003
Posts: 130
yes andi, aruna gaaru.
This is narasimharao konjeti. I got private message from java ranch for ur query. But actually, printing of server side files is not good practice. Any way as per your requirement, u need to write a serverside program i.e. servlet or jsp anything. u need to follow these steps.
1)take mime type of the file(or text) (text/html,word/text,jpeg/image....).
2)and the file byte by byte by using streams.
3)send that bytes to print stream. so u can get solution for ur program. I have written this program 2 years back in servlets, for my client requirement. I am unable to get that program. once i get i will post the code here in forum. my mail id is konjeti4u at the rate of rediffmail.com.
cheers


"Unwise to sweat petty stuff, wise to pet sweaty stuff."
Aruna Velpuri
Greenhorn

Joined: May 07, 2003
Posts: 8
Thanks konjeti garu ,
I am doing same way using JSP.
But when i am reading a word doc it was reading junk characters also.
It is not giving proper output.
My code follows:
<%
try{
String filename = request.getParameter("filename");
response.setContentType( "application/msword" );

BufferedReader bis = null;
BufferedWriter bos = null;
try {
bis = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
bos = new BufferedWriter(out);
char[] buff = new char[4 * 1024]; // 4K buffer
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
}
finally {
if (bis != null) bis.close();
}
}
catch (FileNotFoundException e) {
out.println("File not found: ");
}
catch (IOException e) {
out.println("Problem sending file " + ": " + e.getMessage());
}
%>
 
jQuery in Action, 2nd edition
 
subject: Reading word document
 
Similar Threads
Convert .doc to .rtf
Content (MIME)type in websphere
Copy first page of multiple word docs into a single word doc
Non-programmer question RE Redirects
Choices.txt - Uml required/recommended? Word format?