aspose file tools*
The moose likes JSP and the fly likes .pptx and .docx  problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark ".pptx and .docx  problem" Watch ".pptx and .docx  problem" New topic
Author

.pptx and .docx problem

suchit pandya
Ranch Hand

Joined: Oct 27, 2009
Posts: 43
In my application we use Sinmple MVC2 model. When i allow .pptx and .docx. i set its content type properly at JSP page but at the time of opening it always displays 2 alerts as "Content in this file is currepted. Document can not be opened." After clicking ok it shows another alert that content can be recovered if you trust on this source then click "YES".

After clicking yes document is being displayed properly. How could i avoid thi proble. And there is also another issue that after allowing txt document HTML code appears in this document.

DocX
lStrContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

PPTX
lStrContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

Thanks in Advance
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
Once set the MIME content type, are you writing the contents on the outputStream?


love your job and not your company;
...because you never know when your company will stop loving you!
suchit pandya
Ranch Hand

Joined: Oct 27, 2009
Posts: 43
allBytesInBlob =(byte[])request.getAttribute("content");
OutputStream out1 = response.getOutputStream();
if(allBytesInBlob!=null)
{
out1.write(allBytesInBlob);
out1.flush();
}

I am doing this.
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
Where are you streaming .docx/.pptx contents?

...while adding code, please use code tags
suchit pandya
Ranch Hand

Joined: Oct 27, 2009
Posts: 43
Sorry.. and actually i am new coder... so i dont know about standards
i wrote that code after seting content type.

I am fetching content type from another file. I am getting right content type at
JSP also.



after this code i am doing

manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
Have you ensured that request.getAttribute("content") is returning you file contents? I don't know why are you setting the complete file object into the memory because if its physically present on the server, you could have read it using usual file I/O.
suchit pandya
Ranch Hand

Joined: Oct 27, 2009
Posts: 43
but if it is not returning right file content then i think file content will not be displayed after alerts. And i didn't understad about setting file object into memory.

in my project all the applications are made by this way and i know little bit that this is not prefred way but please will you give tell me how it should be done or the way you are telling to code?
suchit pandya
Ranch Hand

Joined: Oct 27, 2009
Posts: 43
And thanks for replying.....
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
Here is a sample code which I would have used:


I sincerely don't think so far as it has anything to do with .pptx or .docx format but one thing make sure that your client must have appropriate file viewer otherwise on windows, it will show the popup of unknown file format and will prompt user to select appropriate application to open the file.
suchit pandya
Ranch Hand

Joined: Oct 27, 2009
Posts: 43
but in my application when uer attaches any thing with mail then it is being stored in database in clob or blob fields, and when he wants to get i fetch it from clob and seting in request and getting back on jsp. thats why i wrote that code.
I dont have that file on server. So this method will not work in this case. I also doubt that it may be giving alerts that file is currepted because may be data is getting changed between this. Even after saving this file on PC it gives alert when it is been opened.
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
You can not store any of the MS Office formats in CLOB. You must store them in BLOB as they are binary files. Then you save that file from database to file system and then see if you can open it fine. If this worked, then you just need to stream the BLOB directly on the ServletOutputStream to client. even in this case the code does not change much but just input source will be slightly changed.
Christophe Maillard
Greenhorn

Joined: May 03, 2012
Posts: 2
I had the same problem. I found a solution: specifying the "Content-Length" header as I explain here. So, in JAVA, I just needed to add this line to make it work:



Hope it could help :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: .pptx and .docx problem