📄 pdalogonservlet.java
字号:
/*
* @(#)PdaLogonServlet.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;
public class PdaLogonServlet extends HttpServlet {
static final long serialVersionUID = 1675075694621323211L;
public PdaLogonServlet() {
}
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);
}
myContext.setNoCache(response);
myContext.loadSettings(request);
myContext.setLanguage(request);
String errorText = null;
boolean isLogon = true;
try {
isLogon = myContext.isLogonNeeded(request);
} catch (javax.mail.AuthenticationFailedException afe) {
if (afe.toString().toLowerCase().indexOf("eof on socket") != -1)
throw afe;
else
errorText = myContext.getI18nString("_str_auth_failed");
}
myContext.setRichContent(false);
if(!isLogon) {
if(myContext.getDelayedMessage() != null) {
Context.forward(this, request, response, "/pda_compose?action=delayed");
} else {
Context.forward(this, request, response, "/pda_list");
}
}
PdaPage pdaPage = new PdaPage();
pdaPage.setTitle(myContext.getI18nString("_str_login_title"));
//Logo
pdaPage.addPane(myContext.getPdaLogo());
//Title
PdaPane pdaPane = new PdaPane();
pdaPane.setColor(PdaPane.COLOR_CCCCCC);
pdaPane.setHeight("20");
pdaPane.setContent("<font size=\"3\" face=\"arial, tahoma, verdana\"><strong>" +
myContext.getI18nString("_str_login_title") + "</strong></font>");
pdaPage.addPane(pdaPane);
//Menu
StringBuffer sb = new StringBuffer();
sb.append("<a href=\"./logon?ui=pc\"><font size=\"3\">").append(myContext.getI18nString("_str_full_version")).append("</font></a>");
sb.append("<br>");
sb.append("<font size=\"3\">");
for (java.util.Enumeration pn = myContext.langProps.propertyNames(); pn
.hasMoreElements();) {
String pkey = (String) pn.nextElement();
String pvalue = myContext.langProps.getProperty(pkey)
.replaceAll("\\s", " ");
if (pkey.equalsIgnoreCase(myContext.lang)) {
sb.append(pvalue).append(" ");
} else {
sb.append("<a href=\"./pda_logon?lang=").append(pkey)
.append("\">").append(pvalue).append(
"</a> ");
}
}
sb.append("</font>");
PdaPane menuPane = new PdaPane();
menuPane.setColor(PdaPane.COLOR_FFFFFF);
menuPane.setContent(sb.toString());
pdaPage.addPane(menuPane);
//Hint
if (errorText != null) {
sb = new StringBuffer();
sb.append("<strong><font size=\"3\" color=\"red\">").append(
errorText).append("</font></strong>");
pdaPane = new PdaPane();
pdaPane.setColor(PdaPane.COLOR_CCCCCC);
pdaPane.setContent(sb.toString());
pdaPage.addPane(pdaPane);
} else if (myContext.getDelayedMessage() != null) {
sb = new StringBuffer();
sb.append("<strong><font size=\"3\" color=\"#ffff00\">")
.append(myContext.getI18nString("_str_hint_delayed"))
.append("</font></strong>");
pdaPane = new PdaPane();
pdaPane.setColor(PdaPane.COLOR_CCCCCC);
pdaPane.setContent(sb.toString());
pdaPage.addPane(pdaPane);
}
// Main page
sb = new StringBuffer();
sb.append("<form action=\"./pda_logon\" method=\"post\">");
sb.append("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#999999\" width=\"100%\">");
sb.append("<tr>");
sb.append("<td bgcolor=\"#ccccff\">").append(myContext.getI18nString("_str_username")).append("</td>");
sb.append("<td bgcolor=\"#eeeeff\"><input type=\"text\" name=\"user\" size=\"16\"></td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<td bgcolor=\"#ccccff\">").append(myContext.getI18nString("_str_password")).append("</td>");
sb.append("<td bgcolor=\"#eeeeff\"><input type=\"password\" name=\"pass\" size=\"15\"></td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<td bgcolor=\"#eeeeff\"> </td>");
sb.append("<td bgcolor=\"#eeeeff\"><input type=\"submit\" value=\"").append(myContext.getI18nString("_str_login_btn")).append("\"></td>");
sb.append("</tr>");
sb.append("</table>");
sb.append("</form>");
pdaPane = new PdaPane();
pdaPane.setColor(PdaPane.COLOR_9999CC);
pdaPane.setContent(sb.toString());
pdaPage.addPane(pdaPane);
//Sublogo
pdaPane = new PdaPane();
pdaPane.setColor(PdaPane.COLOR_CCFF99);
pdaPane.setHeight("20");
pdaPane.setContent("<font size=\"3\" color=\"#999966\" face=\"arial, tahoma, verdana\"><strong><i>"
+ myContext.getSenderDomain() + "</i></strong></font>");
pdaPage.addPane(pdaPane);
pdaPage.show(out);
out.flush();
out.close();
} catch (Exception e) {
try {
Context.sendErrorRedirect(this, request, response, "/pda_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 + -