• 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

Reading word document

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Aruna Velpuri
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Aruna Velpuri
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
}
%>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic