最近在項目中遇到用ntko插件生成的mht格式的文件,在Iframe中顯示時,mht文件不能解析,後臺編碼原樣輸出。
<div id="showMhtDiv" style="width:100%; height:600px">
<iframe id="showMhtIFrame" name="showMhtIFrame" frameborder="0" style="width:100%;height:100%;" src="example.mht"></iframe>
</div>
在客戶端用瀏覽器打開時顯示內容:
MIME-Version: 1.0 Content-Location: file:///C:/268BA210/temp.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="gb2312"....
在IE瀏覽器下單獨打開該mht文件沒有問題,嵌入頁面中顯示如上內容。原因時瀏覽器再解析網頁時遇到.mht格式的文件不知道如何進行解析。在web.xml中配置如下代碼即可正確解析mht文件
<mime-mapping> <extension>mht</extension> <mime-type>text/x-mht</mime-type> </mime-mapping>
若爲大格式文件時可用如下配置
<mime-mapping> <extension>mht</extension> <mime-type>message/rfc822</mime-type> </mime-mapping>