📄 acntformservlet.java
字号:
/*
* @(#)AcntFormServlet.java
*
* Copyright (C) 2007 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 AcntFormServlet extends HttpServlet {
static final long serialVersionUID = 3335075694621323002L;
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.isAdminLoggedIn()) {
Context.forward(this, request, response, "/admin");
}
myContext.setNoCache(response);
//Get parameters
String action = request.getParameter("action");
if(action == null)
action = "";
String id = request.getParameter("id");
String user_id = request.getParameter("user_id");
String domain_id = request.getParameter("domain_id");
String account = request.getParameter("account");
String comments = request.getParameter("comments");
if(id == null)
id = "";
if(user_id == null)
user_id = "";
if(domain_id == null)
domain_id = "";
if(account == null)
account = "";
if(comments == null)
comments = "";
if(action.equalsIgnoreCase("insert") || action.equalsIgnoreCase("update") ||
action.equalsIgnoreCase("edit") || action.equalsIgnoreCase("delete"))
{
try {
myContext.storage.logon();
olivax.webmail.Account acnt = new olivax.webmail.Account();
if(action.equalsIgnoreCase("insert") || action.equalsIgnoreCase("update")) {
if(action.equalsIgnoreCase("update"))
acnt.id = id;
acnt.userId = user_id;
acnt.domainId = domain_id;
acnt.account = account;
acnt.comments = comments;
myContext.storage.saveAccount(acnt);
Context.forward(this, request, response, "/acnt_form?action=new&user_id=" + user_id);
} else if(action.equalsIgnoreCase("delete")) {
myContext.storage.deleteAccount(id);
Context.forward(this, request, response, "/acnt_list");
} else if(action.equalsIgnoreCase("edit")) {
acnt = myContext.storage.getAccount(id);
user_id = acnt.userId;
domain_id = acnt.domainId;
account = acnt.account;
comments = acnt.comments;
}
} finally {
myContext.storage.close();
}
}
if(action.equalsIgnoreCase("new")) {
domain_id = "";
account = "";
comments = "";
}
// 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_acnt_form_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("<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 = 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_acnt_form_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=\"./acnt_form?action=search&user_id=").append(user_id).append("\">").append(myContext.getI18nString("_str_acnt_search_link")).append("</a> \r\n");
sb.append("<a href=\"./acnt_form?action=new&user_id=").append(user_id).append("\">").append(myContext.getI18nString("_str_acnt_new_link")).append("</a> \r\n");
sb.append("<a href=\"./user_form?action=search\">").append(myContext.getI18nString("_str_user_search_link")).append("</a> \r\n");
sb.append("<a href=\"./dom_form?action=search\">").append(myContext.getI18nString("_str_dom_search_link")).append("</a> \r\n");
sb.append("<a href=\"./admin\">").append(myContext.getI18nString("_str_admin_link")).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);
// Main pane
sb = new StringBuffer();
if(action.equalsIgnoreCase("search")) {
sb.append("<form action=\"./acnt_list\" method=\"post\">");
sb.append("<input type=\"hidden\" name=\"action\" value=\"search\">");
} else {
sb.append("<form action=\"./acnt_form\" method=\"post\">");
}
sb.append("<input type=\"hidden\" name=\"user_id\" value=\"").append(user_id).append("\">");
if(action.equalsIgnoreCase("new")) {
sb.append("<input type=\"hidden\" name=\"action\" value=\"insert\">");
} else if(action.equalsIgnoreCase("edit")) {
sb.append("<input type=\"hidden\" name=\"action\" value=\"update\">");
sb.append("<input type=\"hidden\" name=\"id\" value=\"").append(id).append("\">");
}
sb.append("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\" class=\"basic\">");
sb.append("<tr>");
sb.append("<td class=\"hdr\" bgcolor=\"#ccccff\" width=\"110\"><font size=\"2\">").append(myContext.getI18nString("_str_acnt_domain_id")).append(":</font></td>");
sb.append("<td class=\"data\" bgcolor=\"#eeeeff\">");
sb.append("<select name=\"domain_id\">");
if(domain_id.equals(""))
sb.append("<option value=\"\" selected></option>");
try {
myContext.storage.logon();
java.util.Vector list = myContext.storage.getDomainList(null, null, null);
for(java.util.Enumeration en = list.elements(); en.hasMoreElements();) {
olivax.webmail.Domain domain = (olivax.webmail.Domain)en.nextElement();
String selected = "";
if(domain_id.equals(domain.id))
selected = "selected";
sb.append("<option value=\"").append(domain.id).append("\" ").append(selected).append(">").append(domain.name).append("</option>");
}
} finally {
myContext.storage.close();
}
sb.append("</select>");
sb.append("</td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<td class=\"hdr\" bgcolor=\"#ccccff\" width=\"110\"><font size=\"2\">").append(myContext.getI18nString("_str_acnt_account")).append(":</font></td>");
sb.append("<td class=\"data\" bgcolor=\"#eeeeff\">");
sb.append("<input type=\"text\" name=\"account\" size=\"40\" value=\"").append(account).append("\">");
sb.append("</td>");
sb.append("</tr>");
sb.append("<tr>");
sb.append("<td class=\"hdr\" bgcolor=\"#ccccff\" width=\"110\"><font size=\"2\">").append(myContext.getI18nString("_str_acnt_comment")).append(":</font></td>");
sb.append("<td class=\"data\" bgcolor=\"#eeeeff\">");
sb.append("<input type=\"text\" name=\"comments\" size=\"40\" value=\"").append(comments).append("\">");
sb.append("</td>");
sb.append("</tr>");
if(action.equalsIgnoreCase("search")) {
sb.append("<tr>");
sb.append("<td class=\"hdr\" bgcolor=\"#ccccff\" width=\"110\"><font size=\"2\">").append(myContext.getI18nString("_str_acnt_sort_order")).append(":</font></td>");
sb.append("<td class=\"data\" bgcolor=\"#eeeeff\">");
sb.append("<select name=\"sort_order\">");
sb.append("<option value=\"account\" selected>").append(myContext.getI18nString("_str_acnt_account")).append("</option>");
sb.append("<option value=\"comments\">").append(myContext.getI18nString("_str_acnt_comment")).append("</option>");
sb.append("</select>");
sb.append("</td>");
sb.append("</tr>");
}
sb.append("</table><br>");
if(action.equalsIgnoreCase("search")) {
sb.append("<input type=\"submit\" value=\"").append(myContext.getI18nString("_str_acnt_search")).append("\">");
} else {
sb.append("<input type=\"submit\" value=\"").append(myContext.getI18nString("_str_acnt_save")).append("\">");
}
sb.append("</form>");
webPane = new WebPane();
webPane.setColor(WebPane.COLOR_9999CC);
webPane.setHeight("200");
webPane.setContent(sb.toString());
webPage.addPane(webPane);
//Menu
webPage.addPane(menuPane);
webPage.show(out);
sb = new StringBuffer();
sb.append("</body>\r\n");
sb.append("</html>\r\n");
out.print(sb.toString());
out.flush();
out.close();
} 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 + -