• 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

.pptx and .docx problem

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once set the MIME content type, are you writing the contents on the outputStream?
 
suchit pandya
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you streaming .docx/.pptx contents?

...while adding code, please use code tags
 
suchit pandya
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And thanks for replying.....
 
manoj r patil
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic