aspose file tools*
The moose likes Servlets and the fly likes mhtml file with images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "mhtml file with images" Watch "mhtml file with images" New topic
Author

mhtml file with images

Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
I have a mhtml file with embedded images. It is stored in a folder in local file system. I have a servlet in my web app that reads this .mht file using plain old file IO. This servlet sets the Content-Type to
message/rfc822
and then writes what it read from .mht file to the response. Problem is when client receives the response, it cannot see the image, appears as broken link. What is the correct Content-Type to be set for .mht files or there something else needs to be done?

Thanks


_ __ _ __ _ __ _<br />SCJP 1.4 (95%) | SCWCD 1.4 (79%)<br />Artificial intelligence is no match for natural stupidity.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

According to this this format is not widely accepted among the popular browsers.

Are you sure your browser can show these files?
Have you tried hitting it locally?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
Yes, I tried it locally. My browser IE can show the html and images fine.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you save the file (as streamed by the servlet) to your local hard drive, can you still open it and view it with your browser?
If not, maybe the file is being corrupted in the streaming process.

Also, are you setting the Content-Disposition header?
MSIE often disregards the Content-Type header and tries to figure out what the file type is by its file extension. Maybe setting a file name with an .mhtml ext will be enough for the browser to figure out what it is.
Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
Ben,

Does not look like the file is getting corrupted. If I do view source, only thing looks like is image data missing.

Setting

does not make any difference.

If I try the same thing in Firefox, it tries to download the file. But, if I set it to open automatically without asking, then Firefox saves the file in C:\temp and then opens it from C:\temp in a new tab using IE plug-in.

Interesting part is when I view source of this page (from IE tab), it does not have image data either, but image shows up. Looking at the properties of the image it indicates it's location is
mhtml:file://C:\temp\a.mhtml
.

Even if it works on Firefox, it does not resolve my problem as application suppose to be IE compatible. Did it out of curiosity.

Thanks
Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
I found what was the problem. If the .mhtml file has spaces in the name, then images do not show up. Otherwise it works! Only thing I need to set is content-type to message/rfc822.

Can I say stupid MS bug? (mhtml being MS invented format)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It could just be that your code doesn't support spaces in the file name.



The resulting header value should have quotes around the file name if you want spaces to be supported.

Try:
vijay makam
Ranch Hand

Joined: Sep 06, 2008
Posts: 31
Dear Deb,

I tried reading a .mht file from a servlet and writing it to the response using BufferedInputStream . I have set the content-type to "message/rfc822".
But when I execute the servlet a blank page is displayed in the browser. Do I need to set anything else.

Kindly guide me as you were able to read and send the response to the client.


Regards,
vijay
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: mhtml file with images