How to write the content from document file to jsp page
Joined: Dec 17, 2006
hai all, I have a ms word file in server side. when client requests for that file the content of the file should be displayed in jsp as the same in document file.Because it should only be allowed to read and should be restricted from saving.
I tried by saving the word file as html but the image are not displayed.Also I tried by writing the bytes of the file to response output stream, it's ok for text but image not displayed properly.
In both the case I used text/html as MIME type.
how it should be done ? Any idea's ?
Joined: Feb 28, 2007
setContentType() method sets the content type of the data that is being sent. Iit does not fire any magical translator that would translate the stuffs to the desired format.
response.setContentType("application/msword"); will allow the content of word format to be displayed under word container.
Joined: Dec 17, 2006
Yes you are right, that's why I haven't tried application/msword since it opens with word the file could be copied which is not allowed as per the requirement.
My idea is to open it in jsp so it can be prevented from copying by disabling the properties of the window in which it is opened.
Any suggestions? [ October 17, 2008: Message edited by: mahudees waran ]
If you are going to send a Word document to the client, you cannot prevent the user from saving a copy of it. There are no magic tricks like "open in JSP". So you'll have to review your requirements to correspond with reality.
Good luck with that. Even if you manage to convert the Word doc into a decent HTML file, once it gets displayed on my browser all I have to do is File | Save Page As.. and I can save the file. And even if you manage to turn off that browser capability, I have several other ways of saving the contents. Now, all of this "saving" is to my PC, not to the server. Similarly, if Word displays a document embedded within the browser, and the user uses the File | Save menu, the document is saved only to the user's PC - the document on the server is not updated.
I bring this up because your post was not clear as to what "saving" you were attempting to prevent - saving to the server or saving to the client. As a general rule, saving to the server is not possible (unless you go to the effort to make that possible, usually by providing an upload capability), and preventing saving to the client is not possible. [ October 17, 2008: Message edited by: Peter Johnson ]
To be clear the requirement says that the file content should be viewed by the user but the user should not be allowed to save a copy of the content.
I tried by disabling the menubar, right click event's in the browser window in which it is opened.In that part it was ok I was not able to save the content.
The problem is the content displayed is not same as the word file the images in the word file are not displayed porperly and also with some text alignment issues.
Is that will be correct way to convert the word document to image and displaying the image?
I tried and,the problem with this was the image is too large to display the document size is nearly 260kb but image ranges upto 3000kb so I'm unable to show the image.The image is not displayed while the 10kb size image is displayed properly.