?? attachmentbodypart.java
字號:
package fengyun.Fastmail.beans;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import java.io.InputStream;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* 附件體
* @author fengyun
* @version 1.01
*/
public class AttachmentBodyPart {
private BodyPart bodypart = null;
public AttachmentBodyPart(BodyPart bp) {
this.bodypart = bp;
}
/**
* 輸出到HttpResponse
*/
public void writeTo(HttpServletResponse response){
if (bodypart !=null) {
try {
String strFilename = bodypart.getFileName();
if(strFilename == null)
response.setContentType(bodypart.getContentType());
else
response.setContentType(bodypart.getContentType() + ";filename=\"" + bodypart.getFileName() + "\"");
response.setHeader("Content-Disposition",bodypart.getDisposition());
bodypart.getDataHandler().writeTo(response.getOutputStream());
//bodypart.writeTo(response.getOutputStream());
response.getOutputStream().close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
/** public String getContentType() {
try{
return bodypart.getContentType();
}catch(MessagingException e){
return "Unknown Type";
}
}
public String getFileName() {
try {
return bodypart.getFileName();
}
catch(MessagingException e) {
return "Unknown Filename";
}
} **/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -