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

📄 listservlet.java

📁 一个简单的java邮件系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @(#)ListServlet.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 ListServlet extends HttpServlet {

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

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = null;
		try {
			request.setCharacterEncoding(Context.clntCp);
			response.setContentType("text/html; charset=" + 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);
			}			
			if(!myContext.isLoggedIn()) {
				Context.forward(this, request, response, "/logon"); 
			}
			myContext.setNoCache(response);
			// Get parameters
			String sPg = request.getParameter("pg");
			int iPg = -1;
			try {
				if (sPg != null)
					iPg = Integer.parseInt(sPg);
			} catch (Exception e) {
			}

			String sSort = request.getParameter("sort");
			int iSort = oliva.mail.List.SORT_NONE;
			if (sSort != null) {
				try {
					iSort = Integer.parseInt(sSort);
					myContext.mailBean.setSort(iSort);
				} catch (Exception e) {
				}
			}

			String action = request.getParameter("action");
			if (action != null) {
				if (action.equalsIgnoreCase("delete")) {
					myContext.deleteMessages(request);
					Context.forward(this, request, response, "/list?action=none&pg="
							+ String.valueOf(iPg));
					return;
				}
			}

			//Main page
		    StringBuffer sb = new StringBuffer();
		    sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n");
		    sb.append("<html>\r\n");
		    sb.append("<head>\r\n");
		    sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=").append(Context.clntCp).append("\">\r\n");
//		    sb.append("<meta http-equiv=\"Content-Language\" content=\"ru-RU\">\r\n");
		    sb.append("<meta HTTP-EQUIV=\"PRAGMA\" content=\"NO-CACHE\">\r\n");
		    sb.append("<title>\r\n");
		    sb.append(myContext.getI18nString("_str_list_title")).append("\r\n");
		    sb.append("</title>\r\n");
		    sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"./oliva.css\">\r\n");
		    sb.append("</head>\r\n");
		    
		    sb.append("<script language=\"JavaScript\">\r\n");
		    sb.append("<!--\r\n");
		    sb.append("var bcheck = true;\r\n");
		    sb.append("function selAll() {\r\n");
		    sb.append("  var listForm = document.getElementById(\"listform\");\r\n");
		    sb.append("  for(var i = 0; i < listForm.elements.length; i++) {\r\n");
		    sb.append("    if(listForm.elements[i].type == \"checkbox\") {\r\n");
		    sb.append("      listForm.elements[i].checked = bcheck;\r\n");
		    sb.append("    }\r\n");
		    sb.append("  }\r\n");
		    sb.append("  bcheck = !bcheck;\r\n");
		    sb.append("}\r\n");
		    sb.append("// -->\r\n");  
		    sb.append("</script>\r\n");
		    
		    sb.append("<body link=\"#000033\" alink=\"#000033\" vlink=\"#000033\">\r\n");
		    out.print(sb.toString());

		    //Logo		   
		    WebPage webPage = new WebPage();
		    webPage.addPane(myContext.getWebLogo());

		    //Title
		    WebPane webPane = new WebPane();		    
		    webPane.setColor(WebPane.COLOR_CCCCCC);
		    webPane.setWidth("100%");
		    webPane.setHeight("35");
		    webPane.setContent("<font size=\"3\" face=\"arial, tahoma, verdana\"><strong>" +
		    		myContext.getI18nString("_str_list_title") + "</strong></font>");
		    webPage.addPaneToSameRow(webPane);		    

		    //Sublogo
		    webPane = new WebPane();
		    webPane.setColor(WebPane.COLOR_CCFF99);
		    webPane.setWidth("20%");
		    webPane.setHeight("35");
		    webPane.setContent("<font size=\"4\" color=\"#999966\" face=\"arial, tahoma, verdana\"><strong><i>"
		    		+ myContext.getSenderDomain() + "</i></strong></font>");
		    webPage.addPaneToSameRow(webPane);		    
		    
		    //Menu
		    sb = new StringBuffer();
		    sb.append("<font size=\"2\">\r\n");
		    sb.append("<a href=\"./compose\">").append(myContext.getI18nString("_str_compose")).append("</a>&nbsp;&nbsp;&nbsp;\r\n");
		    sb.append("<a href=\"./list?pg=").append(String.valueOf(iPg)).append("\">").append(myContext.getI18nString("_str_receive")).append("</a>&nbsp;&nbsp;&nbsp;\r\n");
		    if(myContext._storage_enabled) {
		    	sb.append("<a href=\"./addr_form?action=search\">").append(myContext.getI18nString("_str_addr_list_link")).append("</a>&nbsp;&nbsp;&nbsp;\r\n");
		    }
		    sb.append("<a href=\"./logon?action=logout\">").append(myContext.getI18nString("_str_exit")).append("</a>\r\n");		    		    	    		   
			sb.append("</font>\r\n");
		    
			WebPane menuPane = new WebPane();
			menuPane.setColor(WebPane.COLOR_CCCC99);
			menuPane.setContent(sb.toString());
		    webPage.addPane(menuPane);		    

		    //Hint
		    String folder = request.getParameter("folder");
		    oliva.mail.List list = myContext.mailBean.getMessageList(iPg, folder); 
		    if(myContext.mailBean.getSort() != list.sorted) {
		    	myContext.mailBean.setSort(oliva.mail.List.SORT_NONE);		    	
			    webPane = new WebPane();
			    webPane.setColor(WebPane.COLOR_CCCCCC);
			    webPane.setContent("<font size=\"2\" color=\"#000066\" face=\"Arial, Verdana, Tahoma\"><strong>"
			    		+ myContext.getI18nString("_str_list_sort_limited")
						+ "</strong></font><br/>");
			    webPage.addPane(webPane);		    			    
		    }		    		    
		   		    
		    //Folders, total, pages		    
			sb = new StringBuffer();		    
		    if (list.folders != null) {
				sb.append("<form action=\"./list\" method=\"POST\">\r\n");
		    }					    
		    sb.append("<font size=\"2\"><strong>").append(
					myContext.getI18nString("_str_total_msgs")).append(" ")
					.append(String.valueOf(list.msgCount))
					.append("</strong>&nbsp;&nbsp;&nbsp;\r\n");
		    sb.append("<strong>").append(myContext.getI18nString("_str_pages")).append("</strong> ");
			for (int i = 1; i <= list.pgCount; i++) {
				if (list.pgNo == i)
					sb.append("<strong>").append(i).append("</strong>");
				else
					sb.append("<a href=\"./list?pg=" + i + "\">" + i + "</a>");
				sb.append("&nbsp;");
			}
			sb.append("&nbsp;&nbsp;</font>\r\n");
			if (list.folders != null) {
				sb.append("<select name=\"folder\" value=\"").append(
						list.folder).append("\">\r\n");
				for (int i = 0; i < list.folders.length; i++) {
					String selected = "";
					String folderName = list.folders[i];
					String folderNameLc = folderName.toLowerCase();
					if (folderNameLc.startsWith("inbox."))
						folderName = folderName.substring(6);
					else if (folderNameLc.equals("inbox"))
						folderName = myContext.getI18nString("_str_inbox_folder");
					folderName = folderName.replace('.', '\\');

⌨️ 快捷键说明

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