java中接收邮件的附件无法下载的问题???

shanxmxj 2008-10-09 10:47:29
系统收发邮件用的webmail,框架是ofbiz,数据库是oracle,中间件tomcat

问题是这样的:在收邮件时,附件下载的时候,另存的对话框出不来。

下载附件的代码:
/**
* 下载附件
* @param request HttpServletRequest
* @param response HttpServletResponse
*/

public static void do_showpart(HttpServletRequest request,
HttpServletResponse response) throws
ServletException {
String rootPath ="";
long lStoreHandle = 0;
HttpSession session = request.getSession();
String strAttachId = request.getParameter("attachId");
try {
String strFolder = (String) request.getSession().getAttribute(
"sit.mail.folder");
if (strFolder == null)
strFolder = "INBOX";
GenericDelegator delegator = (GenericDelegator) request.getAttribute(
"delegator");
GenericValue attach = delegator.findByPrimaryKey("Attachment",
UtilMisc.toMap("attachId", new Integer(strAttachId)));
String strFilename = attach.getString("filename");
String ApplicationSystem = (String) session.getAttribute(
"sit.mail.ApplicationSystem"); //应用服务器
if (ApplicationSystem != null &&
"websphere".equals(ApplicationSystem.toLowerCase()))
strFilename = new String(strFilename.getBytes(), "ISO-8859-1");
//tianbj update 2006-04-17
//byte[] content = (byte[]) attach.get("content");
//ByteArrayInputStream is = new ByteArrayInputStream(content);
String cluster = UtilProperties.getPropertyFileValue(
"/office.properties", "system.cluster");
if ("false".equals(cluster.toLowerCase())){
rootPath = UtilProperties.getPropertyFileValue(
"/office.properties", "office.root.path");
}else{
rootPath=rootPath=UtilProperties.getPropertyFileValue(
"/office.properties", "office.protect.mail.path");
}
String filePath = rootPath + "/accessoryDirectory/webmail/" +
String.valueOf(strAttachId) + "/" + strFilename;

FileInputStream fis = new FileInputStream(filePath);
OutputStream cOutputStream;
cOutputStream = response.getOutputStream();
byte[] byteBuffer = new byte[256];
int l26;
response.setHeader("Content-disposition",
"attachment;filename=" + strFilename);
response.setHeader("Filename", strFilename);
while ( (l26 = fis.read(byteBuffer)) != -1) {
cOutputStream.write(byteBuffer, 0, l26);
}
cOutputStream.flush();
cOutputStream.close();
}
catch (Exception e) {
Debug.log(e);
throw new javax.servlet.ServletException(e.toString());
}
}


在本地测试时是没有问题的,本地用的是tomcat的中间件。
而部署到用户的环境上就出问题了。
用户那里服务器是win2003的系统,应用是部署到集群上的,中间件是websphere.

在程序中进行判断了,如果是websphere的话 对附件名称进行转码。
在mail.ini的配置文件中也配置了
[code=INIFile]<entry name="sit.mail.ApplicationSystem" value="websphere" />[/code]
附件存放的路径也没有问题。
请大家帮忙这个附件名称的编码我现在应该怎么转??谢谢了!

...全文
536 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chendong_3010 2012-10-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
哈哈~~问题已经解决。
[/Quote]

你MGB的 问题怎么解决的也不说 。 滚你妈的犊子!
shanxmxj 2008-10-14
  • 打赏
  • 举报
回复
哈哈~~问题已经解决。
shanxmxj 2008-10-09
  • 打赏
  • 举报
回复
还有下载时报的错误信息:

DataSou5744703[         SitControl.java:671:DEBUG] [[[cmd_show] Servlet Starting, doing setup- total:0.0,since last(Begin):0.0]]
[08-10-8 13:13:22:281 CST] 00000024 SystemOut O 5744703[ SitControl.java:801:DEBUG] [[[cmd_show] Setup done, doing Event(s) and View(s)- total:0.0,since last([cmd_show] Servle...):0.0]]
[08-10-8 13:13:22:281 CST] 00000024 SystemOut O 5744703[ RequestHandler.java:155:INFO ] [Processing Request]: cmd_show
[08-10-8 13:13:22:328 CST] 00000024 SystemOut O 5744750[ RequestHandler.java:393:INFO ] servletName=sit, view=t_nf_message
[08-10-8 13:13:22:344 CST] 00000024 SystemOut O :::::::::::::::[GenericEntity:Attachment][attachSize,4][messageUid,10242][description,null][attachType,text/plain][content,[B@7465d01e][filename,null][attachId,10231][contentType,context]
[08-10-8 13:13:27:062 CST] 00000024 SystemOut O 5749484[ SitControl.java:671:DEBUG] [[[cmd_showpart] Servlet Starting, doing setup- total:0.0,since last(Begin):0.0]]
[08-10-8 13:13:27:062 CST] 00000024 SystemOut O 5749484[ SitControl.java:801:DEBUG] [[[cmd_showpart] Setup done, doing Event(s) and View(s)- total:0.0,since last([cmd_showpart] Se...):0.0]]
[08-10-8 13:13:27:062 CST] 00000024 SystemOut O 5749484[ RequestHandler.java:155:INFO ] [Processing Request]: cmd_showpart
[08-10-8 13:13:27:078 CST] 00000024 SystemOut O 5749500[ MailEvent.java:397:INFO ]
java.io.FileNotFoundException: e:\accessoryDirectory\webmail\10232\??????????·???????.doc (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:129)
at java.io.FileInputStream.<init>(FileInputStream.java:89)
at com.sailing.webmail.mail.MailEvent.do_showpart(MailEvent.java:382)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.sailing.core.event.JavaEventHandler.invoke(JavaEventHandler.java:81)
at com.sailing.core.event.JavaEventHandler.invoke(JavaEventHandler.java:67)
at com.sailing.core.control.RequestHandler.runEvent(RequestHandler.java:316)
at com.sailing.core.control.RequestHandler.doRequest(RequestHandler.java:195)
at com.sailing.control.servlet.SitControl.doGet(SitControl.java:809)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1284)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1241)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:136)
at filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:43)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:142)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:121)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:82)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:671)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:89)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1924)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:89)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:472)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:411)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:101)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))


我是根据错误信息判断是附件名称的转码问题,但是转成GBK 或者GB2312也都不行。向高手请教!!在线等

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧