📄 sourceservlet.java
字号:
/*
* @(#)SourceServlet.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 javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class SourceServlet extends HttpServlet {
static final long serialVersionUID = 1675075694621323211L;
public SourceServlet() {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
request.setCharacterEncoding(Context.clntCp);
response.setContentType("text/html; charset=" + Context.clntCp);
HttpSession session = request.getSession();
Context myContext = (Context) session.getAttribute("myContext");
if(myContext == null) {
myContext = new Context();
session.setAttribute("myContext", myContext);
}
if(!myContext.isLoggedIn()) {
Context.forward(this, request, response, "/logon");
}
myContext.setNoCache(response);
// Get parameters
int msgno = Integer.parseInt(request.getParameter("msgno"));
String msguid = request.getParameter("msguid");
if (msguid == null)
msguid = "";
String strPartNo = request.getParameter("partno");
int partno = -1;
if (strPartNo != null)
partno = Integer.parseInt(strPartNo);
javax.servlet.ServletOutputStream os = response.getOutputStream();
response.setHeader("Content-Type", "text/plain");
response.setHeader("Content-Disposition", "filename=msg"
+ String.valueOf(msgno) + ".txt");
if (partno == -1) {
myContext.mailBean.getMessageSource(msgno, msguid, os);
} else {
myContext.getMessage(msgno, msguid, null).getRfc822Part(partno).apiMessage
.writeTo(os);
os.flush();
}
} catch (Exception e) {
try {
Context.sendErrorRedirect(this, request, response, "/error", e);
} 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 + -