This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes How to Open .doc file with in browser ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to Open .doc file with in browser ?" Watch "How to Open .doc file with in browser ?" New topic
Author

How to Open .doc file with in browser ?

P Srini
Greenhorn

Joined: Apr 23, 2009
Posts: 10
Hi guys,

I have a requirement here

When User clicks on a link or a button then I want to display a word document (.doc file ) say his profile to him within the browser

Could you please let me know how to that ?

Thanks,
Srinivas.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

Could you please find a friend to help your English? I'm not sure we can understand what you want to know.

However, Microsoft lost a very large lawsuit (over $500 million) with a small company called Eolas several years ago and as part of the settlement of that lawsuit, Internet Explorer is no longer allowed to open Word Documents, Excel spreadsheets, PDF's and other similar files in the browser window.

So far, Internet Explorer is the only browser that's been restricted that way, not Firefox, Opera, or browsers for other OS's such as Apple's Safari. But in Windows/IE, the browser windows cannot be used and the document is opened in a new window. Older versions of IE did not always get "fixed", so some of them will, but anything that old may have other problems by now.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ad Rajesh
Greenhorn

Joined: Apr 25, 2006
Posts: 21
Hi try this,

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="application/msword; charset=ISO-8859-1">
<title>Index Page</title>
</head>
<body>
<form>
Click here to open the document.
</form>
</body>
</html>

href refers to the path of your document.


SCJP 1.4
SCWCD 5.0
P Srini
Greenhorn

Joined: Apr 23, 2009
Posts: 10
Sorry Mr. Tim, My apologies for the mistake in the Text.

My intension is as you got it right, I want to read a msword document, and show it to the user in the browser itself.
Hi Rajesh,
Thanks for the reply.
I tried the code snippet that you provided, but my browser is asking me for confirmation to open the document in MS Word application.

I think I have to use POI for my requirement. Please let me if there is any simple solution.

Thanks,
Srini.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

POI won't allow you to show the document in the browser. POI creates Word-format documents, but Internet Explorer is forbidden from opening Word documents in its own browser windows, regardless of where they came from or how they were generated.

It's not a technical problem, it's a legal issue. Microsoft isn't allowed to open MS-Office documents in IE windows, even if the documents themselves were created by something other than MS-Office.

You might be able to work around this using Google documents or some sort of mechanism like that. It still wouldn't allow you to actually open "Word" documents, but it might present the document in a form that meets Microsoft's legal limitations while still being close enough for users.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

Actually, the simplest solution is to use Firefox, and not Internet Explorer. Firefox doesn't have that legal restriction.

Unfortunately, a lot of companies won't allow a choice.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Can you explain why it is so important to open the document inside the browser instead of outside the browser?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Open .doc file with in browser ?
 
Similar Threads
Some know how to convert a file. Doc to image using java?
deploying a war in tomcat
reading ms word doc file
upload in jsp
Java Html parser