Topic: JavaMail中关于收取附件的问题

  Print this page

1.JavaMail中关于收取附件的问题 Copy to clipboard
Posted by: adelejxsx
Posted on: 2003-03-11 16:35

用JavaMail收取附件时,我把附件的输入流读到了,但我不想把这个轮作输入流输出到文件中,而是做一个链接,点一下这个链接就用IE打开这个附件(如果IE打得开就在IE中打开,如果找不开就会提示你保存),但我实现不了。有哪位大侠知道帮帮忙,感激不尽!!!!!

2.Re:JavaMail中关于收取附件的问题 [Re: adelejxsx] Copy to clipboard
Posted by: gunrose
Posted on: 2003-03-12 09:59

你做的是web的程序吗?
如果是,给出一个链接给用户,让他点击的时候发出请求,你的控制程序得到请求后再去把输入流写到response输出流,这样用户就得到这个文件.

类似代码:
response.setContentType(abcType);
InputStream input = abc.getInputStream();

byte[] buffer=new byte[input.available()];
input.read(mBuffer);
input.close();

OutputStream out = response.getOutputStream();
out.write(mBuffer);
out.close();

注意abc是你的代码

3.Re:JavaMail中关于收取附件的问题 [Re: adelejxsx] Copy to clipboard
Posted by: adelejxsx
Posted on: 2003-03-14 16:33

谢谢qunrose,现在这个附件可以保存了,但是还有一个问题,就是我保存附件的时候,弹出的保存对话框中的文件名并不是附件的名字,而是显示附件内容的页面的名字(如listAttachment.jsp)。
问题二、一般情况下,IE可以浏览的附件就会直接在IE里打开(如html文件和文本文件),但我这里不会。
大侠帮忙!

4.Re:JavaMail中关于收取附件的问题 [Re: adelejxsx] Copy to clipboard
Posted by: Julian13
Posted on: 2003-03-15 03:54

you can set the HTTP header "Content-Disposition" to set the filename
explicitly in the Save As dialog.
For me, I have been used the value:
"inline; filename=<your file name>.zip".
I knew that people set the value as:
"attachment; filename=<your file name>.zip".

however, I don't know the different between "inline" and "attachment".
Anyway, you can have a try.

5.Re:JavaMail中关于收取附件的问题 [Re: Julian13] Copy to clipboard
Posted by: gunrose
Posted on: 2003-03-16 12:03

在准备好output stream后,写数据信前,加上以下代码:
response.setContentType("text/txt");//for question 2
response.setHeader("Content-disposition", "attachment; filename=" + fileName);// for question 1

这样你的问题就解决了。

常见的部分文件类型列表如下:
Audio
  .aif audio/basic
  .au audio/basic
  .mid audio/basic
  .mp2 audio/mpeg
  .ra application/x-pn-realaudio
  .ram audio/x-pn-realaudio
  .rm application/x-pn-realaudio
  .rpm audio/x-pn-realaudio
  .snd audio/basic
  .vox audio/voxware
  .wav audio/wav

Chemical Structure
  .csm chemical/x-csml
  .emb chemical/x-embl-dl-nucleotide
  .gau chemical/x-gaussian-input
  .mol chemical/x-mdl-molfile
  .mop chemical/x-mopac-input
  .pdb chemical/x-pdb
  .rxn chemical/x-mol-rxnfile

Executable
  .bin application/octet-stream
  .dll application/octet-stream
  .exe application/octet-stream
  .js application/x-javascript
  .ls application/x-javascript
  .mocha application/x-javascript
  .tbk application/toolbook

Image
  .bmp image/x-windows-bmp
  .gif image/gif
  .jpeg image/jpeg
  .jpg image/jpeg
  .tif image/tiff
  .tiff image/tiff

Java Applet
  .class application/x-java-class

Math Application
  .mcd application/x-mathcad
  .mws application/maple
  .m application/matlab
  .nb application/mathmatica

Portable Document
  .pdf application/pdf
  .ps application/postscript
  .eps application/postscript
  .dvi application/postscript

Presentation
  .pot application/vnd.ms-powerpoint
  .pps application/x-mspowerpoint
  .ppt application/ms-powerpoint
  .ppz application/mspowerpoint

Software Source Code
  .c text/txt
  .java text/x-java-source
  .php
  .h text/txt
  .cpp text/txt
  .js application/x-javascript
  .vbp application/
  .vjp text/txt
  .ebp application/
  .pl text/txt

Spreadsheet
  .xls application/excel

Video
  .avi video/msvideo
  .mov video/quicktime
  .mpe video/mpeg
  .mpeg video/mpeg
  .mpg video/mpeg
  .qt video/quicktime
  .rm application/x-pn-realaudio

Web Page
  .htm text/html
  .html text/html

Word Processing Document
  .doc application/msword
  .rtf application/rtf
  .wri application/mswrite
  .tex application/latex

6.Re:JavaMail中关于收取附件的问题 [Re: adelejxsx] Copy to clipboard
Posted by: adelejxsx
Posted on: 2003-03-17 08:59

非常感谢!!!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923