Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write the content from document file to jsp page

 
mahudees waran
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mahudees waran
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Paul Clapham
Sheriff
Posts: 21313
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should be restricted from saving


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 ]
 
mahudees waran
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems you have two problems:

1) How to prevent the user from saving the file. Answer: you can't. Give it up. It doesn't matter what your requirements say -- they can't be met. If the user can see the info, it can be copied.

2) Images not appearing. This one can be solved. I suggest you stop talking about (1) and concentrate on solving (2).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic