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

📄 attachservlet.java

📁 一个简单的java邮件系统
💻 JAVA
字号:
/*
 * @(#)AttachServlet.java
 *
 * Copyright (C) 2006 Sergey Bredikhin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package olivax.webmail;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oliva.common.OlivaUtils;

public class AttachServlet extends HttpServlet {

	static final long serialVersionUID = 1675075694621323211L;	
	
	public AttachServlet() {
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = null;
		try {
			//request.setCharacterEncoding(Context.clntCp);			
			out = response.getWriter();
			HttpSession session = request.getSession();
			Context myContext = (Context) session.getAttribute("myContext");
			if(myContext == null) {
				myContext = new Context();
				session.setAttribute("myContext", myContext);
			}
			response.setHeader("Cache-Control", "max-age=0; must-revalidate");
			//response.setHeader("Cache-Control", "no-store; must-revalidate");
			//response.setHeader("Cache-Control", "no-cache; no-store; must-revalidate");
			//response.setHeader("Cache-Control", "max-age=3600, must-revalidate");			
			String ctnttype = OlivaUtils.nvl(request.getParameter("ctnttype"));
			//String ctnttype = OlivaUtils.nvl(request.getParameter("ctnttype")).replace('@', '/');			
			String charset = request.getParameter("charset");
			//String file = request.getParameter("file");
			if(ctnttype != null)
				response.setHeader("Content-Type", ctnttype + 
						((charset != null)?"; charset=" + charset:""));
			  //response.setHeader("Content-Type", ctnttype + "; charset=" + Context.clntCp);				
			String disp = request.getParameter("disp");
			if (disp != null) {
				if (disp.equalsIgnoreCase("att"))
					response.setHeader("Content-Disposition", "attachment");
			}
			/*
			if(file != null)
				response.setHeader("Content-Disposition", "attachment; filename=" + file);
			*/
			//response.setHeader("Content-Disposition", "attachment");
			myContext.getBinaryPart(Integer.parseInt(request.getParameter("msgno")), 
					request.getParameter("msguid"), Integer.parseInt(request.getParameter("partno")), out); 			
		} catch (Exception e) {
			try {
				if(out != null)
					e.printStackTrace(out);
				else
					e.printStackTrace();
			} catch (Exception exc) {				
				exc.printStackTrace();				
			}
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -