Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't download attachment in IE8(Javamail)
    primarykey
    data
    text
    <p>I can not download attachment in email using IE. Nothing happened. But my code works in Chrome. Here's download code:</p> <pre><code>public String downloadattach() { InputStream attStream = null; OutputStream oStream = null; try { String mailid = getRequest().getParameter("mailid"); String filename = getRequest().getParameter("filename"); MailboxServ serv = new MailboxServImpl(); CmMailbox mailbox = serv.getMailbox(mailid); if (mailbox != null &amp;&amp; mailbox.getCmessageBody() != null) { Session session = Session.getInstance(System.getProperties(), null); InputStream iStream = mailbox.getCmessageBody() .getBinaryStream(); MimeMessage message = new MimeMessage(session, iStream); MailManage mm = new MailManage(); attStream = mm.getAttach(message, filename); if (attStream != null) { getResponse().setContentType("APPLICATION/OCTET-STREAM");//("APPLICATION/x-msdownload"); getResponse().setContentLength(attStream.available()); getResponse().setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\""); byte[] buff = new byte[2048]; oStream = getResponse().getOutputStream(); int count = 0; while ((count = attStream.read(buff, 0, 1024)) &gt; 0) { oStream.write(buff, 0, count); } oStream.flush(); oStream.close(); attStream.close(); oStream = null; } } else { writeMsg(false, "下载附件出错!邮件不存在或该邮件不包含指定附件!"); } } catch (Exception e) { // TODO: handle exception logger.error(e.toString()); writeMsg(false, "下载附件出错!错误:" + e.getMessage()); } finally { if (attStream != null) { try { attStream.close(); } catch (Exception e2) { // TODO: handle exception } } if (oStream != null) { try { oStream.close(); } catch (Exception e2) { // TODO: handle exception } } } return null; } </code></pre> <p>the link to attachment in jsp is :</p> <pre><code>'&lt;a href="downloadattachMail.action?mailid='+mailboxid+ '&amp;filename='+fname+'" target="_blank"&gt;'+fname+'&lt;/a&gt;&amp;nbsp;&amp;nbsp;'+fsize </code></pre> <p>It just opened a new window with link the link(eg: localhost:8081/CMAIL/downloadattachMail.action?mailid=40e4c0b6386e81e801386f0e67ce0018&amp;filename=java-event中文文件.doc), but nothing will happen. And the "save as" menu is also can not work. Is there anything wrong? Thank you!</p> <h1>The download can work under chrome, firefox and IE9. But it just can not work in IE8(maybe can't work in IE7 and IE6 neither).</h1> <p>I've found the reason. But it's very very odd! In order to decode Chinese character, i had changed tomcat's configuration by add:</p> <pre><code> URIEncoding="UTF-8" </code></pre> <p>If the attachment's name is English, all works good(chrome, ie8, ie9, firefox). But if the name have Chinese character, the parameter become mess when using ie8, meanwhile everything is good in chrome, firefox and ie9. I changed tomcat's configure:</p> <pre><code> URIEncoding="GBK" </code></pre> <h1>Ie8 works good but chrome, firefox can't.</h1> <p>I had found the solution and share it to everyone:</p> <p>1). set the whole project to UTF-8, set jsp to utf-8 too. 2). in Js, use "encodeURI()" encode the url. 3). and get it use request.getParameter() to get it. Thank you for your kindness again!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload