⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attachmentbodypart.java

📁 mail sent and revesive system jsp+mysql
💻 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 + -